[opensuse-kernel] novfs: replace MUTEX by sema functions
Avoid old MUTEX macros and use sema instead, which works
for both default and RT kernels.
Signed-off-by: Jan Engelhardt
Hi Jan, On Saturday 06 March 2010 08:21:32 pm Jan Engelhardt wrote:
Avoid old MUTEX macros and use sema instead, which works for both default and RT kernels.
Do you actually need the power of semaphores? Given that they are all initialized to 0 or 1, I have a doubt. Simple mutexes are more efficient. What about using the DEFINE_MUTEX/mutex_lock()/mutex_unlock() API instead?
Signed-off-by: Jan Engelhardt
--- fs/novfs/daemon.c | 9 +++++---- fs/novfs/inode.c | 8 +++++--- fs/novfs/profile.c | 5 +++-- fs/novfs/scope.c | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-)
Index: linux-2.6.33-rt/fs/novfs/daemon.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/daemon.c +++ linux-2.6.33-rt/fs/novfs/daemon.c @@ -110,16 +110,17 @@ static atomic_t Daemon_Open_Count = ATOM
static unsigned long Daemon_Command_Timeout = TIMEOUT_VALUE;
-static DECLARE_MUTEX(DriveMapLock); +static struct semaphore DriveMapLock; static LIST_HEAD(DriveMapList);
int novfs_max_iosize = PAGE_SIZE;
-void novfs_daemon_queue_init() +void novfs_daemon_queue_init(void) { INIT_LIST_HEAD(&Daemon_Queue.list); spin_lock_init(&Daemon_Queue.lock); - init_MUTEX_LOCKED(&Daemon_Queue.semaphore); + sema_init(&DriveMapLock, 1); + sema_init(&Daemon_Queue.semaphore, 0); }
void novfs_daemon_queue_exit(void) @@ -163,7 +164,7 @@ int Queue_Daemon_Command(void *request, que->status = QUEUE_SENDING; que->flags = 0;
- init_MUTEX_LOCKED(&que->semaphore); + sema_init(&que->semaphore, 0);
que->sequence = atomic_inc_return(&Sequence);
Index: linux-2.6.33-rt/fs/novfs/inode.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/inode.c +++ linux-2.6.33-rt/fs/novfs/inode.c @@ -298,11 +298,11 @@ static atomic_t novfs_Inode_Number = ATO struct dentry *novfs_root = NULL; char *novfs_current_mnt = NULL;
-DECLARE_MUTEX(InodeList_lock); +struct semaphore InodeList_lock;
LIST_HEAD(InodeList);
-DECLARE_MUTEX(TimeDir_Lock); +struct semaphore TimeDir_Lock; uint64_t lastTime; char lastDir[PATH_MAX];
@@ -3766,7 +3766,7 @@ struct inode *novfs_get_inode(struct sup id->cntDC = 1;
INIT_LIST_HEAD(&id->DirCache); - init_MUTEX(&id->DirCacheLock); + sema_init(&id->DirCacheLock, 1);
id->FileHandle = 0; id->CacheFlag = 0; @@ -3971,6 +3971,8 @@ int __init init_novfs(void) { int retCode;
+ sema_init(&InodeList_lock, 1); + sema_init(&TimeDir_Lock, 1); lastDir[0] = 0; lastTime = get_nanosecond_time();
Index: linux-2.6.33-rt/fs/novfs/profile.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/profile.c +++ linux-2.6.33-rt/fs/novfs/profile.c @@ -60,7 +60,7 @@ static struct proc_dir_entry *dbg_file = static struct proc_dir_entry *dentry_file = NULL; static struct proc_dir_entry *inode_file = NULL;
-static DECLARE_MUTEX(LocalPrint_lock); +static struct semaphore LocalPrint_lock;
static ssize_t User_proc_write_DbgBuffer(struct file *file, const char __user *buf, size_t nbytes, loff_t *ppos) { @@ -622,8 +622,9 @@ uint64_t get_nanosecond_time() return (retVal); }
-void novfs_profile_init() +void novfs_profile_init(void) { + sema_init(&LocalPrint_lock, 1); if (novfs_procfs_dir) dbg_dir = novfs_procfs_dir; else Index: linux-2.6.33-rt/fs/novfs/scope.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/scope.c +++ linux-2.6.33-rt/fs/novfs/scope.c @@ -633,8 +633,8 @@ char *novfs_scope_dget_path(struct dentr void novfs_scope_init(void) { INIT_LIST_HEAD(&Scope_List); - init_MUTEX(&Scope_Lock); - init_MUTEX_LOCKED(&Scope_Thread_Delay); + sema_init(&Scope_Lock, 1); + sema_init(&Scope_Thread_Delay, 0); kthread_run(Scope_Cleanup_Thread, NULL, "novfs_ST"); }
-- Jean Delvare Suse L3 -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
On Sunday 2010-03-07 13:59, Jean Delvare wrote:
Hi Jan,
On Saturday 06 March 2010 08:21:32 pm Jan Engelhardt wrote:
Avoid old MUTEX macros and use sema instead, which works for both default and RT kernels.
Do you actually need the power of semaphores?
Dunno, I did not write novfs. I just made it compile again. Why is novfs - besides coding style - not upstream anyway? And how does it relate to ncpfs?
Given that they are all initialized to 0 or 1, I have a doubt. Simple mutexes are more efficient. What about using the DEFINE_MUTEX/mutex_lock()/mutex_unlock() API instead? -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
Am 07.03.10 14:10, schrieb Jan Engelhardt:
On Sunday 2010-03-07 13:59, Jean Delvare wrote:
On Saturday 06 March 2010 08:21:32 pm Jan Engelhardt wrote:
Avoid old MUTEX macros and use sema instead, which works for both default and RT kernels.
Do you actually need the power of semaphores?
Dunno, I did not write novfs. I just made it compile again.
Since you replaced DECLARE_MUTEX with it, I'm sure you don't. :) Regards, Bernhard -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
On Sunday 2010-03-07 14:46, Bernhard Walle wrote:
Am 07.03.10 14:10, schrieb Jan Engelhardt:
On Sunday 2010-03-07 13:59, Jean Delvare wrote:
On Saturday 06 March 2010 08:21:32 pm Jan Engelhardt wrote:
Avoid old MUTEX macros and use sema instead, which works for both default and RT kernels.
Do you actually need the power of semaphores?
Dunno, I did not write novfs. I just made it compile again.
Since you replaced DECLARE_MUTEX with it, I'm sure you don't. :)
Eh? -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
Am 07.03.10 14:53, schrieb Jan Engelhardt:
On Sunday 2010-03-07 14:46, Bernhard Walle wrote:
Am 07.03.10 14:10, schrieb Jan Engelhardt:
On Sunday 2010-03-07 13:59, Jean Delvare wrote:
On Saturday 06 March 2010 08:21:32 pm Jan Engelhardt wrote:
Avoid old MUTEX macros and use sema instead, which works for both default and RT kernels.
Do you actually need the power of semaphores?
Dunno, I did not write novfs. I just made it compile again.
Since you replaced DECLARE_MUTEX with it, I'm sure you don't. :)
From your patch: -static DECLARE_MUTEX(DriveMapLock); +static struct semaphore DriveMapLock; So you replaced the old DECLARE_MUTEX() (which is actually a binary semaphore as Jean mentioned) with struct semaphore. Which is not wrong, of course. But it shows that the semaphore was used as mutex, so I don't see a problem with using the new Mutex API as Jean mentioned. Again, your patch is correct. But Jean described a better (more efficent) way. Regards, Bernhard -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
On Sunday 2010-03-07 14:56, Bernhard Walle wrote:
Am 07.03.10 14:53, schrieb Jan Engelhardt:
On Sunday 2010-03-07 14:46, Bernhard Walle wrote:
Am 07.03.10 14:10, schrieb Jan Engelhardt:
On Sunday 2010-03-07 13:59, Jean Delvare wrote:
On Saturday 06 March 2010 08:21:32 pm Jan Engelhardt wrote:
Avoid old MUTEX macros and use sema instead, which works for both default and RT kernels.
Do you actually need the power of semaphores?
Dunno, I did not write novfs. I just made it compile again.
Since you replaced DECLARE_MUTEX with it, I'm sure you don't. :)
From your patch:
-static DECLARE_MUTEX(DriveMapLock); +static struct semaphore DriveMapLock;
So you replaced the old DECLARE_MUTEX() (which is actually a binary semaphore as Jean mentioned) with struct semaphore. Which is not wrong, of course. But it shows that the semaphore was used as mutex, so I don't see a problem with using the new Mutex API as Jean mentioned.
You would have to check whether the sema is held in sleeping, which newmutexes are not allowed to. -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
Am 07.03.10 16:35, schrieb Jan Engelhardt:
So you replaced the old DECLARE_MUTEX() (which is actually a binary semaphore as Jean mentioned) with struct semaphore. Which is not wrong, of course. But it shows that the semaphore was used as mutex, so I don't see a problem with using the new Mutex API as Jean mentioned.
You would have to check whether the sema is held in sleeping, which newmutexes are not allowed to.
include/linux/semaphore.h: #define DECLARE_MUTEX(name) \ struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1) So the initial mutex you want to replace is a semaphore. Just the macros are missing in RT. Okay. include/linux/mutex.h: #define DEFINE_MUTEX(mutexname) \ struct mutex mutexname = __MUTEX_INITIALIZER(mutexname) Okay, Jean was proposing a 'struct mutex'. I was not talking about a rt_mutex (the spinlock replacement). If there's a 3rd mutex flavour ('newmutex') I'm not aware of, please enlight me. Even the RT patch itself does -static DECLARE_MUTEX(console_sem); +static DEFINE_MUTEX(console_mutex); I would wonder if that mutex wouldn't be held while a task sleeps. Regards, Bernhard -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
On Sunday 2010-03-07 17:01, Bernhard Walle wrote:
So you replaced the old DECLARE_MUTEX() (which is actually a binary semaphore as Jean mentioned) with struct semaphore. Which is not wrong, of course. But it shows that the semaphore was used as mutex, so I don't see a problem with using the new Mutex API as Jean mentioned.
You would have to check whether the sema is held in sleeping, which newmutexes are not allowed to.
So the initial mutex you want to replace is a semaphore. Just the macros are missing in RT. Okay.
include/linux/mutex.h: #define DEFINE_MUTEX(mutexname) \ struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
Okay, Jean was proposing a 'struct mutex'. I was not talking about a rt_mutex (the spinlock replacement). If there's a 3rd mutex flavour ('newmutex') I'm not aware of, please enlight me.
"new mutex" is just the "new mutex api" you mentioned up above. - "old mutexes", better known as semaphores used with binary semantics - new mutexes, aka the 2.6.16-introduced struct mutex
Even the RT patch itself does
-static DECLARE_MUTEX(console_sem); +static DEFINE_MUTEX(console_mutex);
I would wonder if that mutex wouldn't be held while a task sleeps.
DEFINE_MUTEX is still a semaphore, so it could in theory. -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
Am 07.03.10 17:11, schrieb Jan Engelhardt:
DEFINE_MUTEX is still a semaphore, so it could in theory.
This is wrong. include/linux/mutex.h: #define DEFINE_MUTEX(mutexname) \ struct mutex mutexname = __MUTEX_INITIALIZER(mutexname) RT -------------------------------------------------------- struct mutex { struct rt_mutex lock; #ifdef CONFIG_DEBUG_LOCK_ALLOC struct lockdep_map dep_map; #endif }; Vanilla ------------------------------------------------------------- struct mutex { /* 1: unlocked, 0: locked, negative: locked, possible waiters */ atomic_t count; spinlock_t wait_lock; struct list_head wait_list; #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP) struct thread_info *owner; #endif #ifdef CONFIG_DEBUG_MUTEXES const char *name; void *magic; #endif #ifdef CONFIG_DEBUG_LOCK_ALLOC struct lockdep_map dep_map; #endif }; Regards, Bernhard -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
On Sunday 2010-03-07 18:03, Bernhard Walle wrote:
Am 07.03.10 17:11, schrieb Jan Engelhardt:
DEFINE_MUTEX is still a semaphore, so it could in theory.
This is wrong.
yeah yeah DECLARE, DEFINE, one's semaphore, one's mutex. It's a grand historical naming fuckup that still has not been cleaned up. -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
On Sunday 07 March 2010 04:35:58 pm Jan Engelhardt wrote:
On Sunday 2010-03-07 14:56, Bernhard Walle wrote:
So you replaced the old DECLARE_MUTEX() (which is actually a binary semaphore as Jean mentioned) with struct semaphore. Which is not wrong, of course. But it shows that the semaphore was used as mutex, so I don't see a problem with using the new Mutex API as Jean mentioned.
You would have to check whether the sema is held in sleeping, which newmutexes are not allowed to.
How that, please? I use "new" mutexes in many drivers, and they do sleep, and this has never been a problem, nor has anyone ever told me this was incorrect. Care to backup your claim? include/linux/mutex.h doesn't mention sleeping constraints at all. -- Jean Delvare Suse L3 -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
On Sunday 2010-03-07 17:56, Jean Delvare wrote:
On Sunday 07 March 2010 04:35:58 pm Jan Engelhardt wrote:
On Sunday 2010-03-07 14:56, Bernhard Walle wrote:
So you replaced the old DECLARE_MUTEX() (which is actually a binary semaphore as Jean mentioned) with struct semaphore. Which is not wrong, of course. But it shows that the semaphore was used as mutex, so I don't see a problem with using the new Mutex API as Jean mentioned.
You would have to check whether the sema is held in sleeping, which newmutexes are not allowed to.
How that, please? I use "new" mutexes in many drivers, and they do sleep, and this has never been a problem, nor has anyone ever told me this was incorrect. Care to backup your claim? include/linux/mutex.h doesn't mention sleeping constraints at all.
Not sleep; but whatever was written in Documentation/mutexes.txt. -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
On Sun, Mar 07, 2010 at 02:10:25PM +0100, Jan Engelhardt wrote:
On Sunday 2010-03-07 13:59, Jean Delvare wrote:
Hi Jan,
On Saturday 06 March 2010 08:21:32 pm Jan Engelhardt wrote:
Avoid old MUTEX macros and use sema instead, which works for both default and RT kernels.
Do you actually need the power of semaphores?
Dunno, I did not write novfs. I just made it compile again.
Why is novfs - besides coding style - not upstream anyway? And how does it relate to ncpfs?
I tried to get it upstream over a year ago, and ran into the following issues: - the code is a major mess - the userspace/kernelspace api is horrible and is tied very tightly to some userspace tools that I could not fix due to them being owned by some other developers - it duplicated a lot of the ncpfs functionality The "right" thing to do is to pick out the pieces of the novfs code that are not in ncpfs and add it to the existing ncpfs codebase. However, in the end, this is a dead end as users are using the cifs interface on their netware servers more and more these days and have migrated away from the novel file system api due to some restrictions that it had. So it's pretty much a chunk of code only in maintance mode, that we provide to users who are stuck using this old technology. Hope this helps explain it better, greg k-h -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
On 3/7/2010 at 16:55, Greg KH
wrote: The "right" thing to do is to pick out the pieces of the novfs code that are not in ncpfs and add it to the existing ncpfs codebase. However, in the end, this is a dead end as users are using the cifs interface on their netware servers more and more these days and have migrated away from the novel file system api due to some restrictions that it had.
That's a lovely theory but I wonder in how many businesses you went to get to this statement? I've seen quite some Netware networks recently and in none was CIFS used as the primary access method (where it was activated it was there for some scanners that can't do novell file systems, but that can do cifs). Dominique -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
On Mon, Mar 08, 2010 at 08:50:04AM +0100, Dominique Leuenberger wrote:
On 3/7/2010 at 16:55, Greg KH
wrote: The "right" thing to do is to pick out the pieces of the novfs code that are not in ncpfs and add it to the existing ncpfs codebase. However, in the end, this is a dead end as users are using the cifs interface on their netware servers more and more these days and have migrated away from the novel file system api due to some restrictions that it had. That's a lovely theory but I wonder in how many businesses you went to get to this statement?
I went to the people who support this product to get this statement :)
I've seen quite some Netware networks recently and in none was CIFS used as the primary access method (where it was activated it was there for some scanners that can't do novell file systems, but that can do cifs).
I'm not disagreeing that there are a lot of Netware networks out there, or that people are not using this code at all. Just that this is not the future of this filesystem and this is why no one has taken the time to get the novfs code merged upstream. Hope this helps, greg k-h -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
On Sun, 2010-03-07 at 13:59 +0100, Jean Delvare wrote:
Hi Jan,
On Saturday 06 March 2010 08:21:32 pm Jan Engelhardt wrote:
Avoid old MUTEX macros and use sema instead, which works for both default and RT kernels.
Do you actually need the power of semaphores? Given that they are all initialized to 0 or 1, I have a doubt. Simple mutexes are more efficient. What about using the DEFINE_MUTEX/mutex_lock()/mutex_unlock() API instead?
Its the "0", that imposes the problem. In RT, you need "ownership" of the mutex. That's why static INIT_MUTEX_LOCKED doesn't work in RT: At static declare time, there is no "owner". Hence the changes to drop DECLARE_MUTEX and change to DEFINE_MUTEX. The proper implementation eliminates INIT_MUTEX_LOCKED and replaces it with DEFINE_MUTEX mutex; .. down(&mutex); Hope that helps clear this part of it up a little. Sven
Signed-off-by: Jan Engelhardt
--- fs/novfs/daemon.c | 9 +++++---- fs/novfs/inode.c | 8 +++++--- fs/novfs/profile.c | 5 +++-- fs/novfs/scope.c | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-)
Index: linux-2.6.33-rt/fs/novfs/daemon.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/daemon.c +++ linux-2.6.33-rt/fs/novfs/daemon.c @@ -110,16 +110,17 @@ static atomic_t Daemon_Open_Count = ATOM
static unsigned long Daemon_Command_Timeout = TIMEOUT_VALUE;
-static DECLARE_MUTEX(DriveMapLock); +static struct semaphore DriveMapLock; static LIST_HEAD(DriveMapList);
int novfs_max_iosize = PAGE_SIZE;
-void novfs_daemon_queue_init() +void novfs_daemon_queue_init(void) { INIT_LIST_HEAD(&Daemon_Queue.list); spin_lock_init(&Daemon_Queue.lock); - init_MUTEX_LOCKED(&Daemon_Queue.semaphore); + sema_init(&DriveMapLock, 1); + sema_init(&Daemon_Queue.semaphore, 0); }
void novfs_daemon_queue_exit(void) @@ -163,7 +164,7 @@ int Queue_Daemon_Command(void *request, que->status = QUEUE_SENDING; que->flags = 0;
- init_MUTEX_LOCKED(&que->semaphore); + sema_init(&que->semaphore, 0);
que->sequence = atomic_inc_return(&Sequence);
Index: linux-2.6.33-rt/fs/novfs/inode.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/inode.c +++ linux-2.6.33-rt/fs/novfs/inode.c @@ -298,11 +298,11 @@ static atomic_t novfs_Inode_Number = ATO struct dentry *novfs_root = NULL; char *novfs_current_mnt = NULL;
-DECLARE_MUTEX(InodeList_lock); +struct semaphore InodeList_lock;
LIST_HEAD(InodeList);
-DECLARE_MUTEX(TimeDir_Lock); +struct semaphore TimeDir_Lock; uint64_t lastTime; char lastDir[PATH_MAX];
@@ -3766,7 +3766,7 @@ struct inode *novfs_get_inode(struct sup id->cntDC = 1;
INIT_LIST_HEAD(&id->DirCache); - init_MUTEX(&id->DirCacheLock); + sema_init(&id->DirCacheLock, 1);
id->FileHandle = 0; id->CacheFlag = 0; @@ -3971,6 +3971,8 @@ int __init init_novfs(void) { int retCode;
+ sema_init(&InodeList_lock, 1); + sema_init(&TimeDir_Lock, 1); lastDir[0] = 0; lastTime = get_nanosecond_time();
Index: linux-2.6.33-rt/fs/novfs/profile.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/profile.c +++ linux-2.6.33-rt/fs/novfs/profile.c @@ -60,7 +60,7 @@ static struct proc_dir_entry *dbg_file = static struct proc_dir_entry *dentry_file = NULL; static struct proc_dir_entry *inode_file = NULL;
-static DECLARE_MUTEX(LocalPrint_lock); +static struct semaphore LocalPrint_lock;
static ssize_t User_proc_write_DbgBuffer(struct file *file, const char __user *buf, size_t nbytes, loff_t *ppos) { @@ -622,8 +622,9 @@ uint64_t get_nanosecond_time() return (retVal); }
-void novfs_profile_init() +void novfs_profile_init(void) { + sema_init(&LocalPrint_lock, 1); if (novfs_procfs_dir) dbg_dir = novfs_procfs_dir; else Index: linux-2.6.33-rt/fs/novfs/scope.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/scope.c +++ linux-2.6.33-rt/fs/novfs/scope.c @@ -633,8 +633,8 @@ char *novfs_scope_dget_path(struct dentr void novfs_scope_init(void) { INIT_LIST_HEAD(&Scope_List); - init_MUTEX(&Scope_Lock); - init_MUTEX_LOCKED(&Scope_Thread_Delay); + sema_init(&Scope_Lock, 1); + sema_init(&Scope_Thread_Delay, 0); kthread_run(Scope_Cleanup_Thread, NULL, "novfs_ST"); }
-- Jean Delvare Suse L3
-- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 03/06/2010 02:21 PM, Jan Engelhardt wrote:
Avoid old MUTEX macros and use sema instead, which works for both default and RT kernels.
No. They aren't the "old MUTEX macros", they're used *everywhere* in the regular kernel. If the RT kernel doesn't implement them, that's a bug in the RT kernel, not novfs. There was quite a bit of effort put into replacing semaphore sites with mutexes a while ago. Where a while ago is defined as about 4 years ago. Replacing a mutex with a semaphore when the required behavior is mutual exclusion is, quite simply, a regression. - -Jeff
Signed-off-by: Jan Engelhardt
--- fs/novfs/daemon.c | 9 +++++---- fs/novfs/inode.c | 8 +++++--- fs/novfs/profile.c | 5 +++-- fs/novfs/scope.c | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-)
Index: linux-2.6.33-rt/fs/novfs/daemon.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/daemon.c +++ linux-2.6.33-rt/fs/novfs/daemon.c @@ -110,16 +110,17 @@ static atomic_t Daemon_Open_Count = ATOM
static unsigned long Daemon_Command_Timeout = TIMEOUT_VALUE;
-static DECLARE_MUTEX(DriveMapLock); +static struct semaphore DriveMapLock; static LIST_HEAD(DriveMapList);
int novfs_max_iosize = PAGE_SIZE;
-void novfs_daemon_queue_init() +void novfs_daemon_queue_init(void) { INIT_LIST_HEAD(&Daemon_Queue.list); spin_lock_init(&Daemon_Queue.lock); - init_MUTEX_LOCKED(&Daemon_Queue.semaphore); + sema_init(&DriveMapLock, 1); + sema_init(&Daemon_Queue.semaphore, 0); }
void novfs_daemon_queue_exit(void) @@ -163,7 +164,7 @@ int Queue_Daemon_Command(void *request, que->status = QUEUE_SENDING; que->flags = 0;
- init_MUTEX_LOCKED(&que->semaphore); + sema_init(&que->semaphore, 0);
que->sequence = atomic_inc_return(&Sequence);
Index: linux-2.6.33-rt/fs/novfs/inode.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/inode.c +++ linux-2.6.33-rt/fs/novfs/inode.c @@ -298,11 +298,11 @@ static atomic_t novfs_Inode_Number = ATO struct dentry *novfs_root = NULL; char *novfs_current_mnt = NULL;
-DECLARE_MUTEX(InodeList_lock); +struct semaphore InodeList_lock;
LIST_HEAD(InodeList);
-DECLARE_MUTEX(TimeDir_Lock); +struct semaphore TimeDir_Lock; uint64_t lastTime; char lastDir[PATH_MAX];
@@ -3766,7 +3766,7 @@ struct inode *novfs_get_inode(struct sup id->cntDC = 1;
INIT_LIST_HEAD(&id->DirCache); - init_MUTEX(&id->DirCacheLock); + sema_init(&id->DirCacheLock, 1);
id->FileHandle = 0; id->CacheFlag = 0; @@ -3971,6 +3971,8 @@ int __init init_novfs(void) { int retCode;
+ sema_init(&InodeList_lock, 1); + sema_init(&TimeDir_Lock, 1); lastDir[0] = 0; lastTime = get_nanosecond_time();
Index: linux-2.6.33-rt/fs/novfs/profile.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/profile.c +++ linux-2.6.33-rt/fs/novfs/profile.c @@ -60,7 +60,7 @@ static struct proc_dir_entry *dbg_file = static struct proc_dir_entry *dentry_file = NULL; static struct proc_dir_entry *inode_file = NULL;
-static DECLARE_MUTEX(LocalPrint_lock); +static struct semaphore LocalPrint_lock;
static ssize_t User_proc_write_DbgBuffer(struct file *file, const char __user *buf, size_t nbytes, loff_t *ppos) { @@ -622,8 +622,9 @@ uint64_t get_nanosecond_time() return (retVal); }
-void novfs_profile_init() +void novfs_profile_init(void) { + sema_init(&LocalPrint_lock, 1); if (novfs_procfs_dir) dbg_dir = novfs_procfs_dir; else Index: linux-2.6.33-rt/fs/novfs/scope.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/scope.c +++ linux-2.6.33-rt/fs/novfs/scope.c @@ -633,8 +633,8 @@ char *novfs_scope_dget_path(struct dentr void novfs_scope_init(void) { INIT_LIST_HEAD(&Scope_List); - init_MUTEX(&Scope_Lock); - init_MUTEX_LOCKED(&Scope_Thread_Delay); + sema_init(&Scope_Lock, 1); + sema_init(&Scope_Thread_Delay, 0); kthread_run(Scope_Cleanup_Thread, NULL, "novfs_ST"); }
- -- Jeff Mahoney SUSE Labs -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.13 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iEYEARECAAYFAkuTx7AACgkQLPWxlyuTD7IZCQCfc6ohZKCKlRvy3nLc4KP318sA /jwAoJ4aJY8Bx4GeiwjXtS8Mw4UmbDQz =7t5A -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
On Sunday 2010-03-07 16:35, Jeff Mahoney wrote:
On 03/06/2010 02:21 PM, Jan Engelhardt wrote:
Avoid old MUTEX macros and use sema instead, which works for both default and RT kernels.
No.
They aren't the "old MUTEX macros", they're used *everywhere* in the regular kernel. If the RT kernel doesn't implement them, that's a bug in the RT kernel, not novfs.
RT has them... but with different names.
There was quite a bit of effort put into replacing semaphore sites with mutexes a while ago. Where a while ago is defined as about 4 years ago.
So, why do people continue adding bad code with init_MUTEX then?
Replacing a mutex with a semaphore when the required behavior is mutual exclusion is, quite simply, a regression.
- -Jeff
Signed-off-by: Jan Engelhardt
--- fs/novfs/daemon.c | 9 +++++---- fs/novfs/inode.c | 8 +++++--- fs/novfs/profile.c | 5 +++-- fs/novfs/scope.c | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-)
Index: linux-2.6.33-rt/fs/novfs/daemon.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/daemon.c +++ linux-2.6.33-rt/fs/novfs/daemon.c @@ -110,16 +110,17 @@ static atomic_t Daemon_Open_Count = ATOM
static unsigned long Daemon_Command_Timeout = TIMEOUT_VALUE;
-static DECLARE_MUTEX(DriveMapLock); +static struct semaphore DriveMapLock; static LIST_HEAD(DriveMapList);
int novfs_max_iosize = PAGE_SIZE;
-void novfs_daemon_queue_init() +void novfs_daemon_queue_init(void) { INIT_LIST_HEAD(&Daemon_Queue.list); spin_lock_init(&Daemon_Queue.lock); - init_MUTEX_LOCKED(&Daemon_Queue.semaphore); + sema_init(&DriveMapLock, 1); + sema_init(&Daemon_Queue.semaphore, 0); }
void novfs_daemon_queue_exit(void) @@ -163,7 +164,7 @@ int Queue_Daemon_Command(void *request, que->status = QUEUE_SENDING; que->flags = 0;
- init_MUTEX_LOCKED(&que->semaphore); + sema_init(&que->semaphore, 0);
que->sequence = atomic_inc_return(&Sequence);
Index: linux-2.6.33-rt/fs/novfs/inode.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/inode.c +++ linux-2.6.33-rt/fs/novfs/inode.c @@ -298,11 +298,11 @@ static atomic_t novfs_Inode_Number = ATO struct dentry *novfs_root = NULL; char *novfs_current_mnt = NULL;
-DECLARE_MUTEX(InodeList_lock); +struct semaphore InodeList_lock;
LIST_HEAD(InodeList);
-DECLARE_MUTEX(TimeDir_Lock); +struct semaphore TimeDir_Lock; uint64_t lastTime; char lastDir[PATH_MAX];
@@ -3766,7 +3766,7 @@ struct inode *novfs_get_inode(struct sup id->cntDC = 1;
INIT_LIST_HEAD(&id->DirCache); - init_MUTEX(&id->DirCacheLock); + sema_init(&id->DirCacheLock, 1);
id->FileHandle = 0; id->CacheFlag = 0; @@ -3971,6 +3971,8 @@ int __init init_novfs(void) { int retCode;
+ sema_init(&InodeList_lock, 1); + sema_init(&TimeDir_Lock, 1); lastDir[0] = 0; lastTime = get_nanosecond_time();
Index: linux-2.6.33-rt/fs/novfs/profile.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/profile.c +++ linux-2.6.33-rt/fs/novfs/profile.c @@ -60,7 +60,7 @@ static struct proc_dir_entry *dbg_file = static struct proc_dir_entry *dentry_file = NULL; static struct proc_dir_entry *inode_file = NULL;
-static DECLARE_MUTEX(LocalPrint_lock); +static struct semaphore LocalPrint_lock;
static ssize_t User_proc_write_DbgBuffer(struct file *file, const char __user *buf, size_t nbytes, loff_t *ppos) { @@ -622,8 +622,9 @@ uint64_t get_nanosecond_time() return (retVal); }
-void novfs_profile_init() +void novfs_profile_init(void) { + sema_init(&LocalPrint_lock, 1); if (novfs_procfs_dir) dbg_dir = novfs_procfs_dir; else Index: linux-2.6.33-rt/fs/novfs/scope.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/scope.c +++ linux-2.6.33-rt/fs/novfs/scope.c @@ -633,8 +633,8 @@ char *novfs_scope_dget_path(struct dentr void novfs_scope_init(void) { INIT_LIST_HEAD(&Scope_List); - init_MUTEX(&Scope_Lock); - init_MUTEX_LOCKED(&Scope_Thread_Delay); + sema_init(&Scope_Lock, 1); + sema_init(&Scope_Thread_Delay, 0); kthread_run(Scope_Cleanup_Thread, NULL, "novfs_ST"); }
- -- Jeff Mahoney SUSE Labs -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.13 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/
iEYEARECAAYFAkuTx7AACgkQLPWxlyuTD7IZCQCfc6ohZKCKlRvy3nLc4KP318sA /jwAoJ4aJY8Bx4GeiwjXtS8Mw4UmbDQz =7t5A -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
-- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 03/07/2010 10:39 AM, Jan Engelhardt wrote:
On Sunday 2010-03-07 16:35, Jeff Mahoney wrote:
On 03/06/2010 02:21 PM, Jan Engelhardt wrote:
Avoid old MUTEX macros and use sema instead, which works for both default and RT kernels.
No.
They aren't the "old MUTEX macros", they're used *everywhere* in the regular kernel. If the RT kernel doesn't implement them, that's a bug in the RT kernel, not novfs.
RT has them... but with different names.
RT should be fixed then.
There was quite a bit of effort put into replacing semaphore sites with mutexes a while ago. Where a while ago is defined as about 4 years ago.
So, why do people continue adding bad code with init_MUTEX then?
I haven't gone and done a review of it, but it seems like the code that would have had them added recently falls under the category of un- or loosely- maintained. The staging drivers have a bunch of init_MUTEX's in them but those drivers are added without review. - -Jeff
Replacing a mutex with a semaphore when the required behavior is mutual exclusion is, quite simply, a regression.
- -Jeff
Signed-off-by: Jan Engelhardt
--- fs/novfs/daemon.c | 9 +++++---- fs/novfs/inode.c | 8 +++++--- fs/novfs/profile.c | 5 +++-- fs/novfs/scope.c | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-)
Index: linux-2.6.33-rt/fs/novfs/daemon.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/daemon.c +++ linux-2.6.33-rt/fs/novfs/daemon.c @@ -110,16 +110,17 @@ static atomic_t Daemon_Open_Count = ATOM
static unsigned long Daemon_Command_Timeout = TIMEOUT_VALUE;
-static DECLARE_MUTEX(DriveMapLock); +static struct semaphore DriveMapLock; static LIST_HEAD(DriveMapList);
int novfs_max_iosize = PAGE_SIZE;
-void novfs_daemon_queue_init() +void novfs_daemon_queue_init(void) { INIT_LIST_HEAD(&Daemon_Queue.list); spin_lock_init(&Daemon_Queue.lock); - init_MUTEX_LOCKED(&Daemon_Queue.semaphore); + sema_init(&DriveMapLock, 1); + sema_init(&Daemon_Queue.semaphore, 0); }
void novfs_daemon_queue_exit(void) @@ -163,7 +164,7 @@ int Queue_Daemon_Command(void *request, que->status = QUEUE_SENDING; que->flags = 0;
- init_MUTEX_LOCKED(&que->semaphore); + sema_init(&que->semaphore, 0);
que->sequence = atomic_inc_return(&Sequence);
Index: linux-2.6.33-rt/fs/novfs/inode.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/inode.c +++ linux-2.6.33-rt/fs/novfs/inode.c @@ -298,11 +298,11 @@ static atomic_t novfs_Inode_Number = ATO struct dentry *novfs_root = NULL; char *novfs_current_mnt = NULL;
-DECLARE_MUTEX(InodeList_lock); +struct semaphore InodeList_lock;
LIST_HEAD(InodeList);
-DECLARE_MUTEX(TimeDir_Lock); +struct semaphore TimeDir_Lock; uint64_t lastTime; char lastDir[PATH_MAX];
@@ -3766,7 +3766,7 @@ struct inode *novfs_get_inode(struct sup id->cntDC = 1;
INIT_LIST_HEAD(&id->DirCache); - init_MUTEX(&id->DirCacheLock); + sema_init(&id->DirCacheLock, 1);
id->FileHandle = 0; id->CacheFlag = 0; @@ -3971,6 +3971,8 @@ int __init init_novfs(void) { int retCode;
+ sema_init(&InodeList_lock, 1); + sema_init(&TimeDir_Lock, 1); lastDir[0] = 0; lastTime = get_nanosecond_time();
Index: linux-2.6.33-rt/fs/novfs/profile.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/profile.c +++ linux-2.6.33-rt/fs/novfs/profile.c @@ -60,7 +60,7 @@ static struct proc_dir_entry *dbg_file = static struct proc_dir_entry *dentry_file = NULL; static struct proc_dir_entry *inode_file = NULL;
-static DECLARE_MUTEX(LocalPrint_lock); +static struct semaphore LocalPrint_lock;
static ssize_t User_proc_write_DbgBuffer(struct file *file, const char __user *buf, size_t nbytes, loff_t *ppos) { @@ -622,8 +622,9 @@ uint64_t get_nanosecond_time() return (retVal); }
-void novfs_profile_init() +void novfs_profile_init(void) { + sema_init(&LocalPrint_lock, 1); if (novfs_procfs_dir) dbg_dir = novfs_procfs_dir; else Index: linux-2.6.33-rt/fs/novfs/scope.c =================================================================== --- linux-2.6.33-rt.orig/fs/novfs/scope.c +++ linux-2.6.33-rt/fs/novfs/scope.c @@ -633,8 +633,8 @@ char *novfs_scope_dget_path(struct dentr void novfs_scope_init(void) { INIT_LIST_HEAD(&Scope_List); - init_MUTEX(&Scope_Lock); - init_MUTEX_LOCKED(&Scope_Thread_Delay); + sema_init(&Scope_Lock, 1); + sema_init(&Scope_Thread_Delay, 0); kthread_run(Scope_Cleanup_Thread, NULL, "novfs_ST"); }
- -- Jeff Mahoney SUSE Labs -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.13 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/
iEYEARECAAYFAkuTx7AACgkQLPWxlyuTD7IZCQCfc6ohZKCKlRvy3nLc4KP318sA /jwAoJ4aJY8Bx4GeiwjXtS8Mw4UmbDQz =7t5A -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
- -- Jeff Mahoney SUSE Labs -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.13 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iEYEARECAAYFAkuTypIACgkQLPWxlyuTD7K5iwCfbLYf3h9GlAcnQ6dTOfRhjxIR Fd4AoIsJYZUWE7FKn1PevLNvmcX3ooCa =OABO -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
On Sunday 07 March 2010 04:35:12 pm Jeff Mahoney wrote:
On 03/06/2010 02:21 PM, Jan Engelhardt wrote:
Avoid old MUTEX macros and use sema instead, which works for both default and RT kernels.
No.
They aren't the "old MUTEX macros", they're used *everywhere* in the regular kernel. If the RT kernel doesn't implement them, that's a bug in the RT kernel, not novfs.
Err, no, DECLARE_MUTEX is for the old semaphore-backed-up mutexes, this _is_ old and deprecated and fortunately almost unused at this time, except in staging drivers. I would love to see it die once and for all to remove all the remaining confusion. Definitely something for the kernel-janitors project.
There was quite a bit of effort put into replacing semaphore sites with mutexes a while ago. Where a while ago is defined as about 4 years ago. Replacing a mutex with a semaphore when the required behavior is mutual exclusion is, quite simply, a regression.
This is totally correct, but irrelevant here. Jan's patch was essentially expanding macros, not changing the data structure types. -- Jean Delvare Suse L3 -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 03/07/2010 12:26 PM, Jean Delvare wrote:
On Sunday 07 March 2010 04:35:12 pm Jeff Mahoney wrote:
On 03/06/2010 02:21 PM, Jan Engelhardt wrote:
Avoid old MUTEX macros and use sema instead, which works for both default and RT kernels.
No.
They aren't the "old MUTEX macros", they're used *everywhere* in the regular kernel. If the RT kernel doesn't implement them, that's a bug in the RT kernel, not novfs.
Err, no, DECLARE_MUTEX is for the old semaphore-backed-up mutexes, this _is_ old and deprecated and fortunately almost unused at this time, except in staging drivers. I would love to see it die once and for all to remove all the remaining confusion. Definitely something for the kernel-janitors project.
Of course. You're right. I was thinking of DEFINE_MUTEX. - -Jeff - -- Jeff Mahoney SUSE Labs -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.13 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iEYEARECAAYFAkuUGD8ACgkQLPWxlyuTD7KiVQCfdBjSzdR/jnrCQ5yr2QGC3p8K bA0An3N2F+MLK0I9ex4+x26azzM+jCbo =/81G -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org
participants (7)
-
Bernhard Walle
-
Dominique Leuenberger
-
Greg KH
-
Jan Engelhardt
-
Jean Delvare
-
Jeff Mahoney
-
Sven-Thorsten Dietrich