All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Ingo Oeser <ioe-lkml@rameria.de>
Cc: linux-kernel@vger.kernel.org, chaosite@gmail.com,
	Ingo Molnar <mingo@elte.hu>, Andrew Morton <akpm@osdl.org>,
	Linus Torvalds <torvalds@osdl.org>,
	Arjan van de Ven <arjan@infradead.org>,
	Jes Sorensen <jes@trained-monkey.org>, Greg KH <greg@kroah.com>
Subject: Re: [patch 00/62] sem2mutex: -V1
Date: Sat, 14 Jan 2006 14:49:33 +0100	[thread overview]
Message-ID: <1137246573.7634.71.camel@localhost.localdomain> (raw)
In-Reply-To: <200601141422.16760.ioe-lkml@rameria.de>

Ingo,

> semaphore -> mutex is explained a bit in Documentation/mutex-design.txt
> 
> Still missing:
>  - semaphore -> completion

Sempahore to completion is rather simple to explain.

The pattern is mostly like this

threadA
	init_MUTEX_LOCKED(&shared_data_struct.mutex);
	kick_off_threadB();
	down(&shared_data_struct.mutex);

threadB
	wait_for_kick_off();
	do_some_work();
	up(&shared_data_struct.mutex);

The conversion is:

threadA
	init_completion(&shared_data_struct.completion);
	kick_off_threadB();
	wait_for_completion(&shared_data_struct.completion);
	
threadB
	wait_for_kick_off();
	do_some_work();
	complete(&shared_data_struct.completion);

Note, that a completion is only useful, when there are only two parties
involved. The one which initiates an action and the one which signals
completion of the requested action. The action can be some deferred
workload or synchronization of startup / shutdown of related threads.
Its a synchronization mechanism not a concurrency control in the sense
of data protection across multiple potential users of a data structure.

Real life example:

> --- jffs2_fs_sb.h       28 Feb 2005 08:21:06 -0000      1.51
> +++ jffs2_fs_sb.h       19 May 2005 16:12:17 -0000      1.52
> @@ -32,7 +32,7 @@
>         unsigned int flags;
>  
>         struct task_struct *gc_task;    /* GC task struct */
> -       struct semaphore gc_thread_start; /* GC thread start mutex */
> +       struct completion gc_thread_start; /* GC thread start completion */
>         struct completion gc_thread_exit; /* GC thread exit completion port */
>  
>         struct semaphore alloc_sem;     /* Used to protect all the following 
> 
> 
> --- background.c        17 Mar 2005 20:15:58 -0000      1.51
> +++ background.c        19 May 2005 16:18:08 -0000      1.52
> @@ -37,7 +37,7 @@
>         if (c->gc_task)
>                 BUG();

ThreadA
 
> -       init_MUTEX_LOCKED(&c->gc_thread_start);
> +       init_completion(&c->gc_thread_start);
>         init_completion(&c->gc_thread_exit);
>  
>         pid = kernel_thread(jffs2_garbage_collect_thread, c, CLONE_FS|CLONE_FILES);
> @@ -48,7 +48,7 @@
>         } else {
>                 /* Wait for it... */
>                 D1(printk(KERN_DEBUG "JFFS2: Garbage collect thread is pid %d\n", pid));
> -               down(&c->gc_thread_start);
> +               wait_for_completion(&c->gc_thread_start);
>         }
>   
>         return ret;
> @@ -75,7 +75,7 @@
>         allow_signal(SIGCONT);

ThreadB
 
>         c->gc_task = current;
> -       up(&c->gc_thread_start);
> +       complete(&c->gc_thread_start);
>  
>         set_user_nice(current, 10);
> 

Hope that helps

	tglx




  reply	other threads:[~2006-01-14 13:49 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-13 12:44 [patch 00/62] sem2mutex: -V1 Ingo Molnar
2006-01-13 12:59 ` Duncan Sands
2006-01-13 13:06   ` Arjan van de Ven
2006-01-13 13:44   ` Ingo Molnar
2006-01-13 18:25     ` Ingo Oeser
2006-01-13 19:56       ` Ingo Molnar
2006-01-13 21:04         ` Matan Peled
2006-01-13 21:25           ` Arjan van de Ven
2006-01-13 22:09             ` Junio C Hamano
2006-01-13 22:13               ` Arjan van de Ven
2006-01-14 13:22           ` Ingo Oeser
2006-01-14 13:49             ` Thomas Gleixner [this message]
2006-01-14 13:16         ` Ingo Oeser
2006-01-14 13:31           ` Arjan van de Ven
2006-01-14 13:38             ` Ingo Molnar
2006-01-13 13:23 ` Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1137246573.7634.71.camel@localhost.localdomain \
    --to=tglx@linutronix.de \
    --cc=akpm@osdl.org \
    --cc=arjan@infradead.org \
    --cc=chaosite@gmail.com \
    --cc=greg@kroah.com \
    --cc=ioe-lkml@rameria.de \
    --cc=jes@trained-monkey.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.