9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] kenfs question?
@ 2010-02-06 16:12 Venkatesh Srinivas
  2010-02-06 16:16 ` erik quanstrom
  2010-02-07  0:12 ` Russ Cox
  0 siblings, 2 replies; 9+ messages in thread
From: Venkatesh Srinivas @ 2010-02-06 16:12 UTC (permalink / raw)
  To: 9fans

Hi,

I was looking at the sources to kenfs and saw something that confused me -

ilock() (pc/lock.c) calls splhi() and then calls lock(). If that lock were contended,
how would the system not stop? And on a UP system, if you're inside an splhi() block,
why would you need to take an uncontended lock?

Thanks,
-- vs



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] kenfs question?
  2010-02-06 16:12 [9fans] kenfs question? Venkatesh Srinivas
@ 2010-02-06 16:16 ` erik quanstrom
  2010-02-11 13:31   ` Venkatesh Srinivas
  2010-02-07  0:12 ` Russ Cox
  1 sibling, 1 reply; 9+ messages in thread
From: erik quanstrom @ 2010-02-06 16:16 UTC (permalink / raw)
  To: 9fans

> ilock() (pc/lock.c) calls splhi() and then calls lock(). If that lock were contended,
> how would the system not stop? And on a UP system, if you're inside an splhi() block,
> why would you need to take an uncontended lock?

good question.  on a up system, splhi() is sufficient.  on a mp
system, the losing process will spin until the winning process
is finished.

ken fs does need to return to its mp roots.

- erik



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] kenfs question?
  2010-02-06 16:12 [9fans] kenfs question? Venkatesh Srinivas
  2010-02-06 16:16 ` erik quanstrom
@ 2010-02-07  0:12 ` Russ Cox
  2010-02-07  3:02   ` Venkatesh Srinivas
  1 sibling, 1 reply; 9+ messages in thread
From: Russ Cox @ 2010-02-07  0:12 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 757 bytes --]

>
> ilock() (pc/lock.c) calls splhi() and then calls lock(). If that lock were
> contended, how would the system not stop? And on a UP system, if you're
> inside an splhi() block,
> why would you need to take an uncontended lock?
>

ilock is for locks that get used both in normal procs
and in interrupt handlers.  Using splhi makes sure
that the interrupt handler does not get started on the
same cpu while the proc holds the lock, which would
cause a deadlock.

If there were no interrupts involved, the lock would be
managed with lock/unlock instead of ilock/iunlock.

On a uniprocessor you could get away with splhi/splx
instead of ilock/iunlock, but it's easier and more portable
to program as if always on a multiprocessor.

Russ

[-- Attachment #2: Type: text/html, Size: 1068 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] kenfs question?
  2010-02-07  0:12 ` Russ Cox
@ 2010-02-07  3:02   ` Venkatesh Srinivas
  2010-02-07  4:44     ` erik quanstrom
  0 siblings, 1 reply; 9+ messages in thread
From: Venkatesh Srinivas @ 2010-02-07  3:02 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hi,

I guess I wasn't clear; what I was asking was why it was safe to
attempt to take a lock when splhi() at all.

On a UP, if that lock is contended and interrupts are off, you'll
lockup, no? (The timer interrupt handler will never run, reschedule
will never happen, the lock holder will never run).

-- vs



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] kenfs question?
  2010-02-07  3:02   ` Venkatesh Srinivas
@ 2010-02-07  4:44     ` erik quanstrom
  2010-02-07 10:42       ` Charles Forsyth
  0 siblings, 1 reply; 9+ messages in thread
From: erik quanstrom @ 2010-02-07  4:44 UTC (permalink / raw)
  To: 9fans

> I guess I wasn't clear; what I was asking was why it was safe to
> attempt to take a lock when splhi() at all.

because the rule is you can't sleep when holding a lock.

- erik



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] kenfs question?
  2010-02-07  4:44     ` erik quanstrom
@ 2010-02-07 10:42       ` Charles Forsyth
  2010-02-07 12:19         ` Venkatesh Srinivas
  0 siblings, 1 reply; 9+ messages in thread
From: Charles Forsyth @ 2010-02-07 10:42 UTC (permalink / raw)
  To: 9fans

> I guess I wasn't clear; what I was asking was why it was safe to
> attempt to take a lock when splhi() at all.

because such a lock is always taken with splhi, using ilock.
you might find in older code the use of lock in interrupt handlers,
protected by the implicit splhi of interrupt handling, and in
a few cases explicit splhi calls before lock.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] kenfs question?
  2010-02-07 10:42       ` Charles Forsyth
@ 2010-02-07 12:19         ` Venkatesh Srinivas
  0 siblings, 0 replies; 9+ messages in thread
From: Venkatesh Srinivas @ 2010-02-07 12:19 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Sun, Feb 7, 2010 at 5:42 AM, Charles Forsyth <forsyth@terzarima.net> wrote:
>> I guess I wasn't clear; what I was asking was why it was safe to
>> attempt to take a lock when splhi() at all.
>
> because such a lock is always taken with splhi, using ilock.
> you might find in older code the use of lock in interrupt handlers,
> protected by the implicit splhi of interrupt handling, and in
> a few cases explicit splhi calls before lock.

Ah, okay. I didn't realize that.

Perhaps it'd be clearer if ilock/iunlock took a different type than lock/unlock?

Thanks!
-- vs



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] kenfs question?
  2010-02-06 16:16 ` erik quanstrom
@ 2010-02-11 13:31   ` Venkatesh Srinivas
  2010-02-11 14:55     ` erik quanstrom
  0 siblings, 1 reply; 9+ messages in thread
From: Venkatesh Srinivas @ 2010-02-11 13:31 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Sat, Feb 6, 2010 at 11:16 AM, erik quanstrom <quanstro@quanstro.net> wrote:
>> ilock() (pc/lock.c) calls splhi() and then calls lock(). If that lock were contended,
>> how would the system not stop? And on a UP system, if you're inside an splhi() block,
>> why would you need to take an uncontended lock?
>
> good question.  on a up system, splhi() is sufficient.  on a mp
> system, the losing process will spin until the winning process
> is finished.
>
> ken fs does need to return to its mp roots.
>

Did kenfs ever run on MP systems and use >1 CPU?

-- vs



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] kenfs question?
  2010-02-11 13:31   ` Venkatesh Srinivas
@ 2010-02-11 14:55     ` erik quanstrom
  0 siblings, 0 replies; 9+ messages in thread
From: erik quanstrom @ 2010-02-11 14:55 UTC (permalink / raw)
  To: 9fans

> > ken fs does need to return to its mp roots.
> >
>
> Did kenfs ever run on MP systems and use >1 CPU?

yes.  on the "power" mips boxes it did:

http://www.fywss.com/plan9/plan9v2faq.html#smp

if you spend some time with the code, you'll notice that it's
designed for a fair number of processors.

- erik



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-02-11 14:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-06 16:12 [9fans] kenfs question? Venkatesh Srinivas
2010-02-06 16:16 ` erik quanstrom
2010-02-11 13:31   ` Venkatesh Srinivas
2010-02-11 14:55     ` erik quanstrom
2010-02-07  0:12 ` Russ Cox
2010-02-07  3:02   ` Venkatesh Srinivas
2010-02-07  4:44     ` erik quanstrom
2010-02-07 10:42       ` Charles Forsyth
2010-02-07 12:19         ` Venkatesh Srinivas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).