Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1170269

Re: [RFC][PATCH 09/13] hotplug: Replace hotplug lock with percpu-rwsem

From Oleg Nesterov <oleg@redhat.com>
Newsgroups linux.kernel
Subject Re: [RFC][PATCH 09/13] hotplug: Replace hotplug lock with percpu-rwsem
Date 2015-06-23 01:00 +0200
Message-ID <pEiR3-XU-1@gated-at.bofh.it> (permalink)
References <pE91n-3zX-3@gated-at.bofh.it> <pE91o-3zX-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 06/22, Peter Zijlstra wrote:
>
> The cpu hotplug lock is a rwsem with read-in-write and read-in-read
> recursion. Implement it as such.

And this patch fixes the problem afaics. Currently cpu_hotplug_begin()
can livelock because it doesn't stop the new readers. With this patch
this is no longer possible.


> -static inline void percpu_down_read(struct percpu_rw_semaphore *sem)
> +static inline void _percpu_down_read(struct percpu_rw_semaphore *sem)
>  {
>  	might_sleep();
>
> -	rwsem_acquire_read(&sem->rw_sem.dep_map, 0, 0, _RET_IP_);
> -
>  	preempt_disable();
>  	/*
>  	 * We are in an RCU-sched read-side critical section, so the writer
> @@ -46,6 +44,12 @@ static inline void percpu_down_read(stru
>  	 */
>  }
>
> +static inline void percpu_down_read(struct percpu_rw_semaphore *sem)
> +{
> +	rwsem_acquire_read(&sem->rw_sem.dep_map, 0, 0, _RET_IP_);
> +	_percpu_down_read(sem);
> +}

...

>  void get_online_cpus(void)
>  {
>  	might_sleep();
> -	if (cpu_hotplug.active_writer == current)
> +
> +	/* read in write recursion */
> +	if (cpu_hotplug.writer == current)
> +		return;
> +
> +	/* read in read recursion */
> +	if (current->cpuhp_ref++)
>  		return;
> -	cpuhp_lock_acquire_read();
> -	mutex_lock(&cpu_hotplug.lock);
> -	atomic_inc(&cpu_hotplug.refcount);
> -	mutex_unlock(&cpu_hotplug.lock);
> +
> +	lock_map_acquire_read(&cpu_hotplug.rwsem.rw_sem.dep_map);
> +	_percpu_down_read(&cpu_hotplug.rwsem);
>  }

Confused... Why do we need _percpu_down_read()? Can't get_online_cpus()
just use percpu_down_read() ?

Yes, percpu_down_read() is not recursive, like the normal down_read().
But this does not matter because we rely on ->cpuhp_ref anyway?


> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -1410,6 +1410,8 @@ static struct task_struct *copy_process(
>  	p->sequential_io_avg	= 0;
>  #endif
>
> +	cpu_hotplug_init_task(p);

This is probably unnecessary, copy_process() should not be called under
get_online_cpus().

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC][PATCH 09/13] hotplug: Replace hotplug lock with percpu-rwsem Peter Zijlstra <peterz@infradead.org> - 2015-06-22 14:30 +0200
  Re: [RFC][PATCH 09/13] hotplug: Replace hotplug lock with  percpu-rwsem Oleg Nesterov <oleg@redhat.com> - 2015-06-23 01:00 +0200
    [PATCH 0/3] percpu-rwsem: introduce percpu_rw_semaphore->recursive  mode Oleg Nesterov <oleg@redhat.com> - 2015-06-29 02:00 +0200
      [PATCH 2/3] percpu-rwsem: don't use percpu_rw_semaphore->rw_sem to  exclude writers Oleg Nesterov <oleg@redhat.com> - 2015-06-29 02:00 +0200
      [PATCH 3/3] percpu-rwsem: introduce percpu_rw_semaphore->recursive  mode Oleg Nesterov <oleg@redhat.com> - 2015-06-29 02:00 +0200
      [PATCH 1/3] rcusync: introduce rcu_sync_struct->exclusive mode Oleg Nesterov <oleg@redhat.com> - 2015-06-29 02:00 +0200

csiph-web