Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F109105168
D21626.id62009.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D21626.id62009.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,61 @@
* 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;
+ sleepq_add(&fp->f_vnread_flags, NULL, "vofflock", 0, 0);
+ sleepq_wait(&fp->f_vnread_flags, PUSER -1);
+ 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);
+ MPASS(fp->f_vnread_flags & FOFFSET_LOCK_WAITING);
+ fp->f_vnread_flags = 0;
+ sleepq_broadcast(&fp->f_vnread_flags, SLEEPQ_SLEEP, 0, 0);
+ sleepq_release(&fp->f_vnread_flags);
}
void
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Feb 1, 8:41 PM (14 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16390337
Default Alt Text
D21626.id62009.diff (2 KB)
Attached To
Mode
D21626: vfs: scale foffset_lock
Attached
Detach File
Event Timeline
Log In to Comment