Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F109141550
D21626.id62036.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D21626.id62036.diff
View Options
Index: sys/kern/vfs_vnops.c
===================================================================
--- sys/kern/vfs_vnops.c
+++ sys/kern/vfs_vnops.c
@@ -71,6 +71,7 @@
#include <sys/resourcevar.h>
#include <sys/rwlock.h>
#include <sys/sx.h>
+#include <sys/sleepqueue.h>
#include <sys/sysctl.h>
#include <sys/ttycom.h>
#include <sys/conf.h>
@@ -667,8 +668,9 @@
off_t
foffset_lock(struct file *fp, int flags)
{
- struct mtx *mtxp;
+ volatile short *flagsp;
off_t res;
+ short state;
KASSERT((flags & FOF_OFFSET) == 0, ("FOF_OFFSET passed"));
@@ -685,52 +687,63 @@
* According to McKusick the vn lock was protecting f_offset here.
* It is now protected by the FOFFSET_LOCKED flag.
*/
- mtxp = mtx_pool_find(mtxpool_sleep, fp);
- mtx_lock(mtxp);
- if ((flags & FOF_NOLOCK) == 0) {
- while (fp->f_vnread_flags & FOFFSET_LOCKED) {
- fp->f_vnread_flags |= FOFFSET_LOCK_WAITING;
- msleep(&fp->f_vnread_flags, mtxp, PUSER -1,
- "vofflock", 0);
+ flagsp = &fp->f_vnread_flags;
+ if (atomic_cmpset_acq_short(flagsp, 0, FOFFSET_LOCKED))
+ return (fp->f_offset);
+
+ sleepq_lock(&fp->f_vnread_flags);
+ state = *flagsp;
+ for (;;) {
+ if ((state & FOFFSET_LOCKED) == 0) {
+ if (!atomic_fcmpset_acq_short(flagsp, &state,
+ FOFFSET_LOCKED))
+ continue;
+ break;
+ }
+ if ((state & FOFFSET_LOCK_WAITING) == 0) {
+ if (!atomic_fcmpset_acq_short(flagsp, &state,
+ state | FOFFSET_LOCK_WAITING))
+ continue;
}
- fp->f_vnread_flags |= FOFFSET_LOCKED;
+ DROP_GIANT();
+ sleepq_add(&fp->f_vnread_flags, NULL, "vofflock", 0, 0);
+ sleepq_wait(&fp->f_vnread_flags, PUSER -1);
+ PICKUP_GIANT();
+ state = *flagsp;
}
res = fp->f_offset;
- mtx_unlock(mtxp);
+ sleepq_release(&fp->f_vnread_flags);
return (res);
}
void
foffset_unlock(struct file *fp, off_t val, int flags)
{
- struct mtx *mtxp;
+ volatile short *flagsp;
+ short state;
KASSERT((flags & FOF_OFFSET) == 0, ("FOF_OFFSET passed"));
-#if OFF_MAX <= LONG_MAX
- if ((flags & FOF_NOLOCK) != 0) {
- if ((flags & FOF_NOUPDATE) == 0)
- fp->f_offset = val;
- if ((flags & FOF_NEXTOFF) != 0)
- fp->f_nextoff = val;
- return;
- }
-#endif
-
- mtxp = mtx_pool_find(mtxpool_sleep, fp);
- mtx_lock(mtxp);
if ((flags & FOF_NOUPDATE) == 0)
fp->f_offset = val;
if ((flags & FOF_NEXTOFF) != 0)
fp->f_nextoff = val;
- if ((flags & FOF_NOLOCK) == 0) {
- KASSERT((fp->f_vnread_flags & FOFFSET_LOCKED) != 0,
- ("Lost FOFFSET_LOCKED"));
- if (fp->f_vnread_flags & FOFFSET_LOCK_WAITING)
- wakeup(&fp->f_vnread_flags);
- fp->f_vnread_flags = 0;
- }
- mtx_unlock(mtxp);
+
+ if ((flags & FOF_NOLOCK) != 0)
+ return;
+
+ flagsp = &fp->f_vnread_flags;
+ state = *flagsp;
+ if ((state & FOFFSET_LOCK_WAITING) == 0 &&
+ atomic_cmpset_rel_short(flagsp, state, 0))
+ return;
+
+ sleepq_lock(&fp->f_vnread_flags);
+ MPASS((fp->f_vnread_flags & FOFFSET_LOCKED) != 0);
+ MPASS((fp->f_vnread_flags & FOFFSET_LOCK_WAITING) != 0);
+ fp->f_vnread_flags = 0;
+ sleepq_broadcast(&fp->f_vnread_flags, SLEEPQ_SLEEP, 0, 0);
+ sleepq_release(&fp->f_vnread_flags);
}
void
Index: sys/sys/file.h
===================================================================
--- sys/sys/file.h
+++ sys/sys/file.h
@@ -156,7 +156,7 @@
* Below is the list of locks that protects members in struct file.
*
* (a) f_vnode lock required (shared allows both reads and writes)
- * (f) protected with mtx_lock(mtx_pool_find(fp))
+ * (f) updated with atomics and blocking on sleepq
* (d) cdevpriv_mtx
* none not locked
*/
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Feb 2, 8:55 AM (20 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16398590
Default Alt Text
D21626.id62036.diff (3 KB)
Attached To
Mode
D21626: vfs: scale foffset_lock
Attached
Detach File
Event Timeline
Log In to Comment