relayfs redux, part 2
PATCH 1/1 relayfs redux, part 2
Hi,
This patch is the result of the latest round of liposuction on relayfs
- the patch size is now 44K, down from 110K and the 200K before that. I'm posting it as a patch against 2.6.10 rather than -mm in order to make it easier to review, but will create one for -mm once the changes have settled down.
The code has been restructured so much that I can't begin to list all the changes, but here are the main ones:
- replaced the ad-hoc and managed modes with the single algorithm suggested by Roman Zippel
- as also suggested by Roman, a relay channel now is really just a container that automatically creates and manages a set of per-cpu channels
- simplified the API, as suggested by many. Here's what it currently looks like:
rchan *relay_open(chanpath, bufsize, nbufs, flags, callbacks);
void relay_close(chan);
void *relay_reserve(chan, length, cpu);
unsigned relay_write(chan, data, length);
void relay_buffers_consumed(chan, bufs_consumed, cpu);
extern void relay_reset(chan);
void relay_commit(buffer, subbuf_idx, count);helper macros:
relay_get_buffer(chan, cpu)
relay_get_padding(buf, subbuf_idx)
relay_get_commit(buf, subbuf_idx)
callbacks:
int buffer_start(buffer, data, prev_subbuf_idx);
int deliver(buffer, subbuf, prev_subbuf_idx);
int fileop_notify(buffer, filp, fileop);I've also made most of the other specific changes people had, but haven't gotten to them all; I'll incorporate those in the next round. Thanks to everyone who looked at the code and pointed out problems.
I've tested this code using a hacked version of the kprobes network packet tracing module that was submitted along with kprobes awhile ago and it seems to work fine, at least on my single proc test machine. Below is a link to the test code - at this point it's a real hack just to test that the basic mechanism works e.g. it doesn't log the padding or take it out when writing to disk, for instance. I'll be doing some SMP stress-testing when I get the chance and once the code settles down and will clean it up for that.
http://prdownloads.sourceforge.net/dprobes/plog.tar.gz?download
Thanks,
Tom
fs/Kconfig | 16 fs/Makefile | 1 fs/relayfs/Makefile | 8 fs/relayfs/buffers.c | 136 +++++++ fs/relayfs/buffers.h | 14 fs/relayfs/inode.c | 477 ++++++++++++++++++++++++++ fs/relayfs/relay.c | 814 +++++++++++++++++++++++++++++++++++++++++++++ fs/relayfs/relay.h | 37 ++ include/linux/relayfs_fs.h | 150 ++++++++ 9 files changed, 1653 insertions(+)
fs/Kconfig +16 -0
@@ -972,6 +972,22 @@ config RAMFS To compile this as a module, choose M here: the module will be called ramfs. +config RELAYFS_FS + tristate "Relayfs file system support" + ---help--- + Relayfs is a high-speed data relay filesystem designed to provide + an efficient mechanism for tools and facilities to relay large + amounts of data from kernel space to user space. It's not useful + on its own, and should only be enabled if other facilities that + need it are enabled, such as for example the Linux Trace Toolkit. + + This file system is also available as a module ( = code which can be + inserted in and removed from the running kernel whenever you want). + The module is called relayfs. If you want to compile it as a + module, say M here and read <file:Documentation/modules.txt>. + + If unsure, say N. + endmenu menu "Miscellaneous filesystems"
fs/Makefile +1 -0
@@ -94,3 +94,4 @@ obj-$(CONFIG_AFS_FS) += afs/ obj-$(CONFIG_BEFS_FS) += befs/ obj-$(CONFIG_HOSTFS) += hostfs/ obj-$(CONFIG_HPPFS) += hppfs/ +obj-$(CONFIG_RELAYFS_FS) += relayfs/
fs/relayfs/Makefile +8 -0
@@ -0,0 +1,8 @@ +# +# relayfs Makefile +# + +obj-$(CONFIG_RELAYFS_FS) += relayfs.o + +relayfs-y := relay.o buffers.o inode.o +
fs/relayfs/buffers.c +127 -0
127 lines not on this page · raw message
fs/relayfs/buffers.h +14 -0
@@ -0,0 +1,14 @@ +#ifndef _BUFFERS_H +#define _BUFFERS_H + +/* This inspired by rtai/shmem */ +#define FIX_SIZE (x) (((x) - 1) & PAGE_MASK) + PAGE_SIZE + +extern void *alloc_rchan_buf (unsigned long size, +struct page ***page_array, +int *page_count); +extern void free_rchan_buf (void *buf, +struct page **page_array, +int page_count); + +#endif /* _BUFFERS_H */
fs/relayfs/inode.c +450 -0
450 lines not on this page · raw message
fs/relayfs/relay.c +867 -0
867 lines not on this page · raw message
fs/relayfs/relay.h +37 -0
@@ -0,0 +1,37 @@ +/* +* fs/relayfs/relay.h +* +* Copyright (C) 1999-2005 - Karim Yaghmour ([email protected]), Opersys inc. +* Copyright (C) 2002, 2003 - Tom Zanussi ([email protected]), IBM Corp +* +* RelayFS internal definitions and declarations +*/ + +#ifndef _RELAY_H +#define _RELAY_H + +/* +* Internal relayfs kernel API, fs/relayfs/relay.c +*/ + +#define mode_continuous (rchan) (((rchan)->flags & RELAY_MODE_CONTINUOUS) ? 1 : 0) + +extern int __relay_mmap_buffer (struct rchan_buf *rchan, +struct vm_area_struct *vma); + +extern int relayfs_create_dir (const char *name, +struct dentry *parent, +struct dentry **dentry); + +extern int relayfs_create_file (const char * name, +struct dentry *parent, +struct dentry **dentry, +void * data, +int mode); + +extern int relayfs_remove_file (struct dentry *dentry); +extern void rchan_buffer_get (struct rchan_buf *rchan); +extern void rchan_buffer_put (struct rchan_buf *rchan); +extern int rchan_buffer_empty (struct rchan_buf *chan); + +#endif /* _RELAY_H */
include/linux/relayfs_fs.h +157 -0
157 lines not on this page · raw message
Signature · 4 lines
Regards, Tom Zanussi <[email protected]> IBM Linux Technology Center/RAS
Quoted 1 line · Tom Zanussi
diff -urpN -X dontdiff linux-2.6.10/fs/Kconfig linux-2.6.10-cur/fs/Kconfig
...
fs/Kconfig config RAMFS · line 987
Quoted 4 lines
fs/Kconfig +4
-0+ This file system is also available as a module ( = code which can be + inserted in and removed from the running kernel whenever you want). + The module is called relayfs. If you want to compile it as a + module, say M here and read <file:Documentation/modules.txt>.
...
This is a real nit, but personally I'd remove the stuff in parens above.
It's not relayfs' job to educate users about what a module is.
I'll try to give some more substantive feedback next week.
Tim
Quoted 6 lines · Tom Zanussi
This patch is the result of the latest round of liposuction on relayfs
- the patch size is now 44K, down from 110K and the 200K before that. I'm posting it as a patch against 2.6.10 rather than -mm in order to make it easier to review, but will create one for -mm once the changes have settled down.
Actually, I'll drop all the relayfs and ltt patches from -mm. They seem to have done their job ;)
When things settle down and the code is ready for a new run, you know where I sit.
Quoted 7 lines · Tom Zanussi
Hi,
This patch is the result of the latest round of liposuction on relayfs
- the patch size is now 44K, down from 110K and the 200K before that. I'm posting it as a patch against 2.6.10 rather than -mm in order to make it easier to review, but will create one for -mm once the changes have settled down.
The logging fast path seems still a bit slow to me. I would like to have a logging macro that is not much worse than a stdio putc, basically something like
get_cpu();
if (buffer space > N) {
memcpy(buffer, input, N);
buffer pointer += N;
} else {
FreeBuffer(input, N);
}
put_cpu();This would need interrupt protection only if interrupts can access it, best you use separate buffers for that too.
-Andi
Quoted 14 lines · Andi Kleen
Quoted 7 lines · Tom Zanussi
Hi,
This patch is the result of the latest round of liposuction on relayfs
- the patch size is now 44K, down from 110K and the 200K before that. I'm posting it as a patch against 2.6.10 rather than -mm in order to make it easier to review, but will create one for -mm once the changes have settled down.The logging fast path seems still a bit slow to me. I would like to have a logging macro that is not much worse than a stdio putc, basically something like
Quoted 9 lines
get_cpu();
if (buffer space > N) {
memcpy(buffer, input, N);
buffer pointer += N;
} else {
FreeBuffer(input, N);
}
put_cpu();I think what we have now is somewhat similar, except that we wanted to separate grabbing a slot in the buffer from the memcpy because some applications such as ltt want to be able to directly write into the slot without having to copy it into another buffer first. How about something like this for relay reserve, with the local_add_return() gone since we're assuming the client protects the buffer properly for whatever it's doing:
relay_reserve(length)
{
if (buffer->offset + length <= bufsize) {
reserved = buffer->data + buffer->offset;
buffer->offset += length;
} else { /* slow path */
reserved = switch_buffer(length);
if (reserved)
buffer->offset += length;
}
return reserved;
}If you set up the channel to use MODE_CONTINUOUS, meaning continuously cycle around the buffer, your logging function or macro would look something like this:
simplest_write(data, length)
{
get_cpu();
reserved = relay_reserve();
memcpy(reserved, data, length);
put_cpu();
}Clients who want to stop logging if the buffers are full would have an extra test for when the reserve fails, which can never happen in continuous mode:
/* uses MODE_NO_OVERWRITE */ltt_write(data, length)
{
local_irq_save();
reserved = relay_reserve();
if (reserved) { /* if NULL, buffer full */
memcpy(reserved, item1, len1);
.
.
.
memcpy(reserved, itemN, lenN);
}
local_irq_restore();
}Quoted 2 lines
This would need interrupt protection only if interrupts can access it, best you use separate buffers for that too.
Not sure what you mean by separate buffers for that too. Can you expand on that a little?
Thanks,
Tom
Quoted 14 lines · Tom Zanussi
Quoted 4 lines
The logging fast path seems still a bit slow to me. I would like to have a logging macro that is not much worse than a stdio putc, basically something like
Quoted 9 lines
get_cpu(); if (buffer space > N) { memcpy(buffer, input, N); buffer pointer += N; } else { FreeBuffer(input, N); } put_cpu();
Quoted 1 line
I think what we have now is somewhat similar, except that we wanted to
It's doing a complicated function call which does who knows what in the logging fast path (I stopped reading after some point) It definitely is not putc !
Quoted 3 lines
separate grabbing a slot in the buffer from the memcpy because some applications such as ltt want to be able to directly write into the slot without having to copy it into another buffer first. How about
If the inline function to log was fast enough it wouldn't need any such hacks.
Note that gcc is quite good at optimizing memcpy, so essentially when you e.g. do log(singleint) it should be roughly equivalent to a int store into the buffer + the check if there is enough buffer space.
Quoted 3 lines
something like this for relay reserve, with the
local_add_return()gone since we're assuming the client protects the buffer properly for whatever it's doing:
I think relay_reserve shouldn't be in the fast path at all.
The simple write should simple be the traditional stdio putc pattern
if (buffer + datalen < bufferend) {
memcpy(buffer, data, datalen);
buffer += datalen;
} else {
flush(buffer, datalen); /* flush takes care of the slow path */
}This is quite fast for the fast path and expands to reasonably compact inline code too.
The only interesting part is how to protect this against interrupts. For that you need an local_irq_save(); local_irq_restore() which can be unfortunately quite costly (P4 is really slow at PUSHF)
That is why I would provide a __ variant of the simple where the caller guarantees no disruption by interrupts.
On preemptive kernel the local_irq_save takes care of CPU preemption, the __ variant should probably disable preemption to avoid mistakes. For non __ it is not needed.
Quoted 5 lines
Quoted 2 lines
This would need interrupt protection only if interrupts can access it, best you use separate buffers for that too.
Not sure what you mean by separate buffers for that too. Can you expand on that a little?
You could avoid the local_irq_save() if you use separate interrupt buffers that are only accessed in non nesting interrupt context (like softirqs) That would require a sorting step at output though. Not sure if it's worth it. The problem is that hardirqs can nest anyways, so it wouldn't work for them. However a lot of important code runs in softirq (like the network stack) where this is true.
-Andi
Quoted 15 lines · Andi Kleen
Quoted 14 lines · Tom Zanussi
Quoted 13 lines
The logging fast path seems still a bit slow to me. I would like to have a logging macro that is not much worse than a stdio putc, basically something like
get_cpu(); if (buffer space > N) { memcpy(buffer, input, N); buffer pointer += N; } else { FreeBuffer(input, N); } put_cpu();
Quoted 6 lines
Quoted 1 line
I think what we have now is somewhat similar, except that we wanted to
It's doing a complicated function call which does who knows what in the logging fast path (I stopped reading after some point) It definitely is not putc !
I agree with your suggestions below, but I just wanted to point out that the only function called in the fast path is local_add_return(), which is just a few lines - the more complicated stuff in switch_buffer() is only called when crossing buffer boundaries.
Quoted 34 lines
Quoted 3 lines
separate grabbing a slot in the buffer from the memcpy because some applications such as ltt want to be able to directly write into the slot without having to copy it into another buffer first. How about
If the inline function to log was fast enough it wouldn't need any such hacks.
Note that gcc is quite good at optimizing memcpy, so essentially when you e.g. do log(singleint) it should be roughly equivalent to a int store into the buffer + the check if there is enough buffer space.
Quoted 3 lines
something like this for relay reserve, with the
local_add_return()gone since we're assuming the client protects the buffer properly for whatever it's doing:I think
relay_reserveshouldn't be in the fast path at all.The simple write should simple be the traditional stdio putc pattern
if (buffer + datalen < bufferend) { memcpy(buffer, data, datalen); buffer += datalen; } else { flush(buffer, datalen); /* flush takes care of the slow path */ }This is quite fast for the fast path and expands to reasonably compact inline code too.
The only interesting part is how to protect this against interrupts. For that you need an
local_irq_save();local_irq_restore()which can be unfortunately quite costly (P4 is really slow at PUSHF)
Quoted 6 lines
That is why I would provide a __ variant of the simple where the caller guarantees no disruption by interrupts.
On preemptive kernel the
local_irq_savetakes care of CPU preemption, the __ variant should probably disable preemption to avoid mistakes. For non __ it is not needed.
OK, makes sense to me - I'll get rid of relay_reserve and replace it with the simple putc write and variant.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
This would need interrupt protection only if interrupts can access it, best you use separate buffers for that too.
Not sure what you mean by separate buffers for that too. Can you expand on that a little?
Quoted 6 lines
You could avoid the
local_irq_save()if you use separate interrupt buffers that are only accessed in non nesting interrupt context (like softirqs) That would require a sorting step at output though. Not sure if it's worth it. The problem is that hardirqs can nest anyways, so it wouldn't work for them. However a lot of important code runs in softirq (like the network stack) where this is true.
You could just create and log into a separate relayfs channel, if you wanted to. Not sure we need to add anything special to support that.
Tom
Quoted 2 lines · Tom Zanussi
OK, makes sense to me - I'll get rid of
relay_reserveand replace it with the simple putc write and variant.
Please don't do that. Instead, bring back the ad-hoc mode code, that's what is was for anyway.
Quoted 2 lines
You could just create and log into a separate relayfs channel, if you wanted to. Not sure we need to add anything special to support that.
Postprocessing doesn't solve world famine ;) As far as LTT goes, splitting events like this makes it impossible to read large traces. Other clients are free to do as they wish.
Karim
Signature · 3 lines
Author, Speaker, Developer, Consultant Pushing Embedded and Real-Time Linux Systems Beyond the Limits http://www.opersys.com || [email protected] || 1-866-677-4546
Quoted 8 lines · Karim Yaghmour
Quoted 2 lines · Tom Zanussi
OK, makes sense to me - I'll get rid of
relay_reserveand replace it with the simple putc write and variant.Please don't do that. Instead, bring back the ad-hoc mode code, that's what is was for anyway.
I don't think they need to be mutually exclusive - we could keep relay_reserve(), but the relay_write() that's currently built on top of relay_reserve() would use the putc code instead. It's complicating the API a bit, but if it makes everyone happy...
Tom
Quoted 4 lines · Tom Zanussi
I don't think they need to be mutually exclusive - we could keep
relay_reserve(), but therelay_write()that's currently built on top ofrelay_reserve()would use the putc code instead. It's complicating the API a bit, but if it makes everyone happy...
Actually I think that this would be a much better use of relay_write(), which is unlikely to be used by any client that requires relay_reserve() to start with. Also, I don't think it complicates the API at all. Compared to the original API, what we've got now is very simple. So it basically boils down to:
- use relay_write() if you want putc-like functionality.
- use relay_reserve() if you want to reserve space and write separately.
This is even better than having a separate ad-hoc mode.
Karim
Signature · 3 lines
Author, Speaker, Developer, Consultant Pushing Embedded and Real-Time Linux Systems Beyond the Limits http://www.opersys.com || [email protected] || 1-866-677-4546
Quoted 3 lines · Andi Kleen
It's doing a complicated function call which does who knows what in the logging fast path (I stopped reading after some point) It definitely is not putc !
I was anticipating some people would have this requirement, and this is why I introduced the ad-hoc mode. Roman asked me to get rid of it because nobody had yet asked for it, so this is why it was dropped. As it is, the implementation you are suggesting is insufficient for LTT, which is relayfs' first formal client. I think that it would be better to provide two underlying mechanisms for relayfs at this point, we had already stripped it as thin as it would go for things like LTT.
Quoted 7 lines
Quoted 3 lines
separate grabbing a slot in the buffer from the memcpy because some applications such as ltt want to be able to directly write into the slot without having to copy it into another buffer first. How about
If the inline function to log was fast enough it wouldn't need any such hacks.
Actually that's not true. There are two problems with this statement:
a- It requires prepackaged data units.
b- It's only useful for fixed-size data units.
Any efficient client that has complex data units will want to write directly into the buffer instead of creating an intermediate package which is then memcopied. With the modified code, we are now forced to create an intermediate package, which is wrong. Also, if the client wants to log variable-size events, he would have to re-implement lots of the writing code.
Note that I really think relay_write() should be dropped altogether. Clients should call on relay_reserve() and do whatever is necessary after that.
Quoted 4 lines
Note that gcc is quite good at optimizing memcpy, so essentially when you e.g. do log(singleint) it should be roughly equivalent to a int store into the buffer + the check if there is enough buffer space.
I understand the point you are trying to make, but I really think that this is best implemented as two separate buffering schemes instead of breaking the existing one (which had already been trimmed down quite thin following Roman's input.)
Quoted 6 lines
You could avoid the
local_irq_save()if you use separate interrupt buffers that are only accessed in non nesting interrupt context (like softirqs) That would require a sorting step at output though. Not sure if it's worth it. The problem is that hardirqs can nest anyways, so it wouldn't work for them. However a lot of important code runs in softirq (like the network stack) where this is true.
For the kind of data sizes we are looking at for LTT (100GBs) splitting buffers is not viable anyway.
Karim
Signature · 3 lines
Author, Speaker, Developer, Consultant Pushing Embedded and Real-Time Linux Systems Beyond the Limits http://www.opersys.com || [email protected] || 1-866-677-4546
fs/relayfs/buffers.h line 12
Quoted 6 lines · Tom Zanussi
fs/relayfs/buffers.h +6
-0+extern void *alloc_rchan_buf (unsigned long size, +struct page ***page_array, +int *page_count); +extern void free_rchan_buf (void *buf, +struct page **page_array, +int page_count);
As these will be "polluting" the global namespace of the kernel, could you add "relayfs_" to the front of them?
Also, any reason why you haven't exported the fops of relayfs so that others can use this in their filesystems (like proc and debugfs)?
Quoted 14 lines
fs/relayfs/relay.c +14
-0+/** +* rchan_create_file - create relay file, including parent directories +* @chanpath: path to file, including filename +* @dentry: result dentry +* @data: data to associate with the file +* +* Returns 0 if successful, negative otherwise. +*/ +static inline int rchan_create_file (const char *chanpath, +struct dentry **dentry, +struct rchan_buf *data) +{ +int err; +const char * fname;
fs/relayfs/relay.c line 497
Quoted 10 lines
fs/relayfs/relay.c +10
-0+struct dentry *topdir; + + err =rchan_create_dir (chanpath, &fname, &topdir); +if (err && (err != -EEXIST )) +return err; + + err =relayfs_create_file (fname, topdir, dentry, data,S_IRUSR ); + +return err; +}
Why not just return the * to the dentry? Gets rid of one paramater...
Also, if a path is passed to this function, when the "channel" is finally torn down, that path is not removed, right? Or did I miss that in the code somewhere?
Quoted 10 lines
fs/relayfs/relay.c +10
-0+/** +* check_attribute_flags - check sanity of channel attributes +* @flags: channel attributes +* +* Returns 0 if successful, negative otherwise. +*/ +static inline int check_attribute_flags (u32 *attribute_flags) +{ +u32 flags = *attribute_flags; +
fs/relayfs/relay.c line 518
Quoted 10 lines
fs/relayfs/relay.c +10
-0+if ((flags &RELAY_MODE_CONTINUOUS ) && + (flags &RELAY_MODE_NO_OVERWRITE )) +return -EINVAL ;/* Can't have it both ways */ + +if (!(flags &RELAY_MODE_CONTINUOUS ) && + !(flags &RELAY_MODE_NO_OVERWRITE )) + *attribute_flags |=RELAY_MODE_CONTINUOUS ;/* Default */ + +return 0 ; +}
Why be nice to your caller? Just force them to get the flags right, and if not, error out, you don't have to provide a "default" as this is a required parameter to start up a channel, right?
Quoted 10 lines
include/linux/relayfs_fs.h +10
-0+/* +* Per-cpu relay channel buffer +*/ +struct rchan_buf +{ +void *start;/* start of channel buffer */ +void *data;/* start of current sub-buffer */ +local_t offset;/* current offset into sub-buffer */ +unsigned bufsize;/* sub-buffer size */ +unsigned alloc_size;/* total buffer size allocated */
include/linux/relayfs_fs.h line 70
Quoted 10 lines
include/linux/relayfs_fs.h +10
-0+unsigned nbufs;/* number of sub-buffers */ +unsigned bufs_produced;/* count of sub-buffers produced */ +unsigned bufs_consumed;/* count of sub-buffers consumed */ +wait_queue_head_t read_wait;/* reader wait queue */ +struct work_struct wake_readers;/* reader wake-up work struct */ +struct rchan_callbacks *cb;/* client callbacks */ +struct work_struct work;/* remove file work struct */ +u32 flags;/* relay channel attributes */ +struct dentry *dentry;/* channel file dentry */ +atomic_t refcount;/* channel refcount */
Please use struct kref for this.
include/linux/relayfs_fs.h line 76
Quoted 6 lines
include/linux/relayfs_fs.h +6
-0+struct page **page_array;/* array of current buffer pages */ +int page_count;/* number of current buffer pages */ +unsigned *padding;/* padding counts per sub-buffer */ +unsigned *commit;/* commit counts per sub-buffer */ +int finalized;/* buffer has been finalized */ +}____cacheline_aligned ;
thanks,
greg k-h
Quoted 11 lines · Greg KH
fs/relayfs/buffers.h line 12
Quoted 6 lines · Tom Zanussi
fs/relayfs/buffers.h +6
-0+extern void *alloc_rchan_buf (unsigned long size, +struct page ***page_array, +int *page_count); +extern void free_rchan_buf (void *buf, +struct page **page_array, +int page_count);As these will be "polluting" the global namespace of the kernel, could you add "
relayfs_" to the front of them?
Quoted 3 lines
Also, any reason why you haven't exported the fops of relayfs so that others can use this in their filesystems (like proc and debugfs)?
No reason - I just forgot. I'll make sure that gets fixed along with all the other things you pointed out here in the next patch.
Thanks,
Tom
Quoted 12 lines · Greg KH
fs/relayfs/buffers.h line 12
Quoted 6 lines · Tom Zanussi
fs/relayfs/buffers.h +6
-0+extern void *alloc_rchan_buf (unsigned long size, +struct page ***page_array, +int *page_count); +extern void free_rchan_buf (void *buf, +struct page **page_array, +int page_count);As these will be "polluting" the global namespace of the kernel, could you add "
relayfs_" to the front of them?
BTW, these functions are in buffers.h which is an internal header to fs/relayfs/*.c files. buffers.h is not included in anything outside. Correct me if I'm wrong, but there is no namespace pollution in that case, right? All that does contribute to namespace pollution is in include/linux/relayfs_fs.h.
Thanks,
Karim
Signature · 3 lines
Author, Speaker, Developer, Consultant Pushing Embedded and Real-Time Linux Systems Beyond the Limits http://www.opersys.com || [email protected] || 1-866-677-4546
Quoted 15 lines · Karim Yaghmour
Quoted 12 lines · Greg KH
fs/relayfs/buffers.h line 12
Quoted 6 lines · Tom Zanussi
fs/relayfs/buffers.h +6
-0+extern void *alloc_rchan_buf (unsigned long size, +struct page ***page_array, +int *page_count); +extern void free_rchan_buf (void *buf, +struct page **page_array, +int page_count);As these will be "polluting" the global namespace of the kernel, could you add "
relayfs_" to the front of them?
Quoted 5 lines
BTW, these functions are in
buffers.hwhich is an internal header tofs/relayfs/*.cfiles.buffers.his not included in anything outside. Correct me if I'm wrong, but there is no namespace pollution in that case, right? All that does contribute to namespace pollution is ininclude/linux/relayfs_fs.h.
When relayfs is built into the kernel, those symbols are then global to the whole static kernel.
Please be nice and rename them.
thanks,
greg k-h
Quoted 4 lines · Greg KH
When relayfs is built into the kernel, those symbols are then global to the whole static kernel.
Please be nice and rename them.
My pleasure :)
Karim
Signature · 3 lines
Author, Speaker, Developer, Consultant Pushing Embedded and Real-Time Linux Systems Beyond the Limits http://www.opersys.com || [email protected] || 1-866-677-4546
Hi,
Quoted 6 lines · Tom Zanussi
fs/relayfs/relay.c +6
-0+static inline int rchan_create_file (const char *chanpath, +struct dentry **dentry, +struct rchan_buf *data) +{ +int err; +const char * fname;
fs/relayfs/relay.c line 497
Quoted 10 lines
fs/relayfs/relay.c +10
-0+struct dentry *topdir; + + err =rchan_create_dir (chanpath, &fname, &topdir); +if (err && (err != -EEXIST )) +return err; + + err =relayfs_create_file (fname, topdir, dentry, data,S_IRUSR ); + +return err; +}
What protects topdir from being removed inbetween?
Why is necessary to let the user create/remove files/dirs at all?
Quoted 33 lines
fs/relayfs/relay.c +32
-0+void *relay_reserve (struct rchan *chan, +unsigned length, +int cpu) +{ +unsigned offset; +struct rchan_buf *buffer; + + buffer =relay_get_buffer (chan, cpu); + +while (1 ) { + offset =local_add_return (&buffer->offset, length); +if (likely (offset + length <= buffer->bufsize)) +break ; + buffer =relay_switch_buffer (buffer, offset, length); +if (buffer ==NULL ) +return NULL ; + } + +return buffer->data + offset; +} + + +unsigned relay_write (struct rchan *chan, +const void *data, +unsigned length) +{ +int cpu; +char *reserved; +unsigned count =0 ; + + cpu =get_cpu (); +
fs/relayfs/relay.c line 803
Quoted 10 lines
fs/relayfs/relay.c +10
-0+ reserved =relay_reserve (chan, length, cpu); +if (reserved) { +memcpy (reserved, data, length); + count = length; + } + +put_cpu (); + +return count; +}
For the first version I would suggest to use just local_irq_save/_restore. Getting it right with local_add_return is not trivial and I'm pretty sure your relay_switch_buffer() gets it wrong, e.g. the caller for whom (offset < bufsize) must close the subbuffer. Also buffer->data in relay_reserve may have become invalid (e.g. by an interrupt just before it).
You can also move all the rchan_buf members which are not written to in the event path and which are common to all channels back to rchan. relay_write should so look more like this:
unsigned int relay_write(struct rchan *chan, const void *data,
unsigned int length)
{
struct rchan_buf *buffer;
unsigned long flags;
local_irq_save(flags);
buffer = chan->buff[smp_processor_id()];
if (unlikely(buffer->offset + length > chan->size)) {
if (relay_switch_buffer(chan, buffer)) {
length = 0;
goto out;
}
}
memcpy(buffer->data + offset, data, length);
buffer->offset += length;
out:
local_irq_restore(flags);
return length;
}relay_reserve() should be more or less obvious from this.
bye, Roman
Quoted 15 lines · Roman Zippel
Hi,
Quoted 11 lines · Tom Zanussi
fs/relayfs/relay.c +11
-0+static inline int rchan_create_file (const char *chanpath, +struct dentry **dentry, +struct rchan_buf *data) +{ +int err; +const char * fname; +struct dentry *topdir; + + err =rchan_create_dir (chanpath, &fname, &topdir); +if (err && (err != -EEXIST )) +return err;
Quoted 8 lines
fs/relayfs/relay.c line 497
Quoted 5 lines
fs/relayfs/relay.c +5
-0+ + err =relayfs_create_file (fname, topdir, dentry, data,S_IRUSR ); + +return err; +}What protects topdir from being removed inbetween?
Why is necessary to let the user create/remove files/dirs at all?
Good point - file/dir creation/removal should only be done by relay_open/close. I'll make sure to fix both of these things.
[...]
Quoted 7 lines
For the first version I would suggest to use just local_irq_save/_restore. Getting it right with
local_add_returnis not trivial and I'm pretty sure yourrelay_switch_buffer()gets it wrong, e.g. the caller for whom (offset < bufsize) must close the subbuffer. Alsobuffer->datainrelay_reservemay have become invalid (e.g. by an interrupt just before it).
Yes, there are a couple of bugs here, but I think they're easily fixed
- thanks for spotting them.
For the buffer->data problem, the value of buffer->data at the time offset is reserved would have to be saved along with it for it to make sense.
For relay_switch_buffer(), only the offset of the first event that didn't fit would be less than bufsize so if there was a check for that i.e. if offset < bufsize, calculate padding, otherwise don't and just continue, the interrupt would continue through and actually accomplish the buffer switch, while the interrupted event would calculate the padding and then exit immediately because of the (offset + length < bufsize) recheck. Both would then loop around again to retry and succeed. Well, I'm not sure that explanation is clear, but it seems like it should work with that small change.
Please let me know if you disagree or see any other problems.
Quoted 2 lines
You can also move all the
rchan_bufmembers which are not written to in the event path and which are common to all channels back to rchan.
Yes, I was actually planning on doing that, but hadn't gotten to it yet.
Thanks,
Tom