Messages in this thread | | | Date | Sat, 19 Dec 2009 09:40:56 -0800 (PST) | From | Linus Torvalds <> | Subject | Re: [PATCH] [1/2] SYSCTL: Make bin_table not const |
| |
On Sat, 19 Dec 2009, Andi Kleen wrote: > > Turn all the bin_tables from const to non-const. This is needed for the next > patch. Unfortunately there were a lot of them, so the patch is rather > large, but it is completely mechanic.
Ouch. I hate this.
I'd much rather have a constant sysctl bin_table.
If the _only_ thing you want to do is to do a "warn-on-once" logic, I would seriously suggest you use a small hash-table instead of turning bin_table non-const.
IOW, d something like this:
#define WARN_ONCE_HASH_BITS (10) #define WARN_ONCE_HASH_SIZE (1<<WARN_ONCE_HASH_BITS)
static DECLARE_BITMAP(warn_once_bitmap, WARN_ONCE_HASH_SIZE);
/* * NOTE! We don't use the SMP-safe bit tests. We simply * don't care enough. */ static void warn_on_bintable(const int *name, int nlen) { unsigned int hash = full_name_hash(name, nlen); hash = hash_32(hash, WARN_ONCE_HASH_BITS); if (__test_and_set_bit(warn_once_bitmap, hash)) return; deprecated_sysctl_warning(name, nlen); }
which should do the right thing in all practical circumstances.
(The above is obviously totally untested, I wrote it in the mail reader, but it's obvious enough what the intent is).
Linus
| |