Project

General

Profile

Actions

Bug #908

closed

mention msleep() in porting_drivers.txt

Added by aoiko over 16 years ago. Updated about 10 years ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
Documentation
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

Description

Any suggestions on how to make this clearer are welcome.

Index: notes/porting_drivers.txt ===================================================================
RCS file: /home/aggelos/imports/vcs/dcvs/doc/notes/porting_drivers.txt,v
retrieving revision 1.3
diff u -p -u -r1.3 porting_drivers.txt
--
notes/porting_drivers.txt 29 Dec 2007 18:35:59 -0000 1.3
+++ notes/porting_drivers.txt 6 Jan 2008 17:40:24 -0000
@ -84,6 +84,24 @ $DragonFly: doc/notes/porting_drivers.tx
call is replaced with
lockmgr(&my_lock, LK_EXCLUSIVE|LK_NOWAIT);

+ On occasion, the FreeBSD code will use mtx_sleep() or msleep()
+ (currently [01/2008], those macros have identical definitions)
+ in order to release a mutex and sleep without missing any
+ wakeups that might occur in between. The DragonFly idiom for
+ this case is to enter a critical section and use tsleep_interlock()
+ to let threads in other cpus know that we're about to go to
+ sleep. In our example, you would substitute

crit_enter();
+ tsleep_interlock(ident);
+ lockmgr(&my_lock, LK_RELEASE);
+ tsleep(ident, flags, "whatever", timeout);
+ crit_exit();
+ lockmgr(&my_lock, LK_EXCLUSIVE);

for
+ msleep(ident, &my_mtx, flags, "whatever", timeout);
+
As for mtx_assert() calls, translate them like this:

mtx_assert(&my_mtx, MA_OWNED) -> KKASSERT(lockstatus(&my_lock, curthread) != 0)
Actions #1

Updated by hsu1 over 16 years ago

Well, we do have a msleep() function. It atomically releases a
lock before sleeping to ensure that no wakeup is missed. It is the
same as the msleep() function that's currently in FreeBSD, except
in FreeBSD it release a mutex lock and in DragonFly it releases a
spin lock. For short critical sections that don't block, substituting
a spinlock and msleep() for a mutex lock and msleep() would be the
most direct way to convert between FreeBSD and DragonFly.

For more complicated critical sections, it might be better to pursue
a different MP-safety strategy entirely, such as per-cpu data along with
crit_enter()/crit_exit(). This has lower overhead and also parallelizes,
rather than serializes, the work load.

Jeffrey
Actions #2

Updated by aoiko over 16 years ago

Unfortunately it was not obvious from the patch context, but the added text
is part of an example of how to convert MTX_DEF FreeBSD mutexes. So I guess
this comment does not apply.

Agreed. The reason I didn't just add an example for MTX_SPIN mutexes is
precisely not to encourage just blindly copying FreeBSD's fine-grained
locking. Explaining alternative strategies and tradeoffs would require
a seperate article of its own though.

Aggelos

Actions #3

Updated by dillon over 16 years ago

:Agreed. The reason I didn't just add an example for MTX_SPIN mutexes is
:precisely not to encourage just blindly copying FreeBSD's fine-grained
:locking. Explaining alternative strategies and tradeoffs would require
:a seperate article of its own though.
:
:Aggelos

Yah, I far prefer that people use lockmgr locks for most porting from
FreeBSD, if only to make debugging far, far easier. They aren't half
bad... over the years I've removed a lot of cruft from the lockmgr API,
it's actually pretty efficient.
The interrupt serializer is the best locking mechanism to use for drivers
which have interrupt service routines, but requires a bit more research
to use properly in a port vs lockmgr locks.
-Matt
Matthew Dillon
<>
Actions #4

Updated by tuxillo over 14 years ago

At least there's a mention to it:
  • MSLEEP/TSLEEP conversion. The DragonFly msleep/tsleep do not have 'PRI'
    priorities. 0 should be used.

Maybe the most common "translation" could be added, and make it clear that there
are situations where it cannot just blindly replaced. Pointing to this ticket
and some documention is also interesting in my opinion.

Actions #5

Updated by sjg about 14 years ago

grab

Actions #6

Updated by sjg about 11 years ago

  • Description updated (diff)

Some more stuff for the porting file...

All mbuf calls use MB_* flags, not M_* flags. e.g. MB_DONTWAIT instead of
M_NOWAIT.

m_collapse(*xxx, M_DONTWAIT, XXX_XXX) -> m_defrag(*xxx, MB_DONTWAIT)

IFQ_DRV_* -> ifq_*

(struct ifnet)->if_flags was split into if_flags and if_drv_flags in FreeBSD,
replace all occurences of if_drv_flags with if_flags and the variable being
assigned from IF_DRV_* to IF_*

Actions #7

Updated by tuxillo about 11 years ago

  • Assignee changed from sjg to tuxillo

Grab

Actions #8

Updated by tuxillo about 10 years ago

  • Description updated (diff)
  • Category set to Documentation
  • Status changed from In Progress to Closed
  • Target version set to 3.8

Hi,

MSLEEP/TSLEEP conversion is already mentioned in doc/porting_drivers.txt

Closing this one.

Cheers,
Antonio Huete

Actions

Also available in: Atom PDF