relay: Use per CPU constructs for the relay channel buffer pointers
PATCH 1/1 relay: Use per CPU constructs for the relay channel buffer pointers
From: Akash Goel <[email protected]>
relay essentially needs to maintain the per CPU array of channel buffer pointers but it manually creates that array.
Instead its better to avail the per CPU constructs, provided by the kernel, to allocate & access the array of pointer to channel buffers.
--- include/linux/relay.h | 16 ++++++----- kernel/relay.c | 74 +++++++++++++++++++++++++++++---------------------- 2 files changed, 51 insertions(+), 39 deletions(-)
include/linux/relay.h +9 -7
@@ -63,7 +63,7 @@ struct rchanstruct kref kref;/* channel refcount */ void *private_data;/* for user-defined data */ size_t last_toobig;/* tried to log event > subbuf size */ -struct rchan_buf *buf[NR_CPUS ];/* per-cpu channel buffers */ +struct rchan_buf **__percpu buf;/* per-cpu channel buffers */ int is_global;/* One global buffer ? */ struct list_head list;/* for channel list */ struct dentry *parent;/* parent dentry passed to open */
@@ -204,7 +204,7 @@ static inline void relay_write(struct rchan *chan,struct rchan_buf *buf;local_irq_save (flags); - buf = chan->buf[smp_processor_id ()]; + buf = *this_cpu_ptr (chan->buf);if (unlikely (buf->offset + length > chan->subbuf_size)) length =relay_switch_subbuf (buf, length);memcpy (buf->data + buf->offset, data, length);
@@ -230,12 +230,12 @@ static inline void __relay_write(struct rchan *chan, {struct rchan_buf *buf; - buf = chan->buf[get_cpu ()]; + buf = *get_cpu_ptr (chan->buf);if (unlikely (buf->offset + length > buf->chan->subbuf_size)) length =relay_switch_subbuf (buf, length);memcpy (buf->data + buf->offset, data, length); buf->offset += length; -put_cpu (); +put_cpu_ptr (chan->buf); }/**
@@ -251,17 +251,19 @@ static inline void __relay_write(struct rchan *chan,*/ static inline void *relay_reserve (struct rchan *chan,size_t length) { -void *reserved; -struct rchan_buf *buf = chan->buf[smp_processor_id ()]; +void *reserved =NULL ; +struct rchan_buf *buf = *get_cpu_ptr (chan->buf);if (unlikely (buf->offset + length > buf->chan->subbuf_size)) { length =relay_switch_subbuf (buf, length);if (!length) -return NULL ; + goto end; } reserved = buf->data + buf->offset; buf->offset += length; +end: +put_cpu_ptr (chan->buf);return reserved; }
kernel/relay.c +42 -32
222 lines not on this page · raw message
Signature · 1 line
1.9.2
Quoted 10 lines · On Thu, Aug 11, 2016 at 12:35:40PM +0530, [email protected] wrote:
From: Akash Goel <[email protected]>
relay essentially needs to maintain the per CPU array of channel buffer pointers but it manually creates that array.
Instead its better to avail the per CPU constructs, provided by the kernel, to allocate & access the array of pointer to channel buffers.Cc Chris Wilson <[email protected]>Cc Tvrtko Ursulin <[email protected]>Signed-off-by Akash Goel <[email protected]>
This has the benefit of being a mechnical change and I could not think of a better way to express the per-cpu indirection.
relay.h should probably include <linux/percpu.h> so that it pulls in the percpu api explicitly.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
PATCH v2 1/1 relay: Use per CPU constructs for the relay channel buffer pointers
From: Akash Goel <[email protected]>
relay essentially needs to maintain the per CPU array of channel buffer pointers but it manually creates that array.
Instead its better to avail the per CPU constructs, provided by the kernel, to allocate & access the array of pointer to channel buffers.
v2: Include <linux/percpu.h> in relay.h so that it pulls in the percpu
api explicitly. (Chris)
--- include/linux/relay.h | 17 +++++++----- kernel/relay.c | 74 +++++++++++++++++++++++++++++---------------------- 2 files changed, 52 insertions(+), 39 deletions(-)
include/linux/relay.h +10 -7
@@ -19,6 +19,7 @@#include <linux/fs.h> #include <linux/poll.h> #include <linux/kref.h> +#include <linux/percpu.h> /* * Tracks changes to rchan/rchan_buf structs
@@ -63,7 +64,7 @@ struct rchanstruct kref kref;/* channel refcount */ void *private_data;/* for user-defined data */ size_t last_toobig;/* tried to log event > subbuf size */ -struct rchan_buf *buf[NR_CPUS ];/* per-cpu channel buffers */ +struct rchan_buf **__percpu buf;/* per-cpu channel buffers */ int is_global;/* One global buffer ? */ struct list_head list;/* for channel list */ struct dentry *parent;/* parent dentry passed to open */
@@ -204,7 +205,7 @@ static inline void relay_write(struct rchan *chan,struct rchan_buf *buf;local_irq_save (flags); - buf = chan->buf[smp_processor_id ()]; + buf = *this_cpu_ptr (chan->buf);if (unlikely (buf->offset + length > chan->subbuf_size)) length =relay_switch_subbuf (buf, length);memcpy (buf->data + buf->offset, data, length);
@@ -230,12 +231,12 @@ static inline void __relay_write(struct rchan *chan, {struct rchan_buf *buf; - buf = chan->buf[get_cpu ()]; + buf = *get_cpu_ptr (chan->buf);if (unlikely (buf->offset + length > buf->chan->subbuf_size)) length =relay_switch_subbuf (buf, length);memcpy (buf->data + buf->offset, data, length); buf->offset += length; -put_cpu (); +put_cpu_ptr (chan->buf); }/**
@@ -251,17 +252,19 @@ static inline void __relay_write(struct rchan *chan,*/ static inline void *relay_reserve (struct rchan *chan,size_t length) { -void *reserved; -struct rchan_buf *buf = chan->buf[smp_processor_id ()]; +void *reserved =NULL ; +struct rchan_buf *buf = *get_cpu_ptr (chan->buf);if (unlikely (buf->offset + length > buf->chan->subbuf_size)) { length =relay_switch_subbuf (buf, length);if (!length) -return NULL ; + goto end; } reserved = buf->data + buf->offset; buf->offset += length; +end: +put_cpu_ptr (chan->buf);return reserved; }
kernel/relay.c +42 -32
222 lines not on this page · raw message
Signature · 1 line
1.9.2
tip-bot for Akash Goel
merge botrelay: Use per CPU constructs for the relay channel buffer pointers
Commit-ID: 1de44797f13b84e793e796c077988a3023391daf Gitweb: http://git.kernel.org/tip/1de44797f13b84e793e796c077988a3023391daf Author: Akash Goel <[email protected]> AuthorDate: Fri, 2 Sep 2016 21:47:38 +0200 Committer: Thomas Gleixner <[email protected]> CommitDate: Tue, 6 Sep 2016 16:20:28 +0200
relay: Use per CPU constructs for the relay channel buffer pointers
relay essentially needs to maintain a per CPU array of channel buffer pointers but it manually creates that array. Instead its better to use the per CPU constructs, provided by the kernel, to allocate & access the array of pointer to channel buffers.
--- include/linux/relay.h | 17 +++++++----- kernel/relay.c | 74 +++++++++++++++++++++++++++++---------------------- 2 files changed, 52 insertions(+), 39 deletions(-)
include/linux/relay.h +10 -7
@@ -19,6 +19,7 @@#include <linux/fs.h> #include <linux/poll.h> #include <linux/kref.h> +#include <linux/percpu.h> /* * Tracks changes to rchan/rchan_buf structs
@@ -63,7 +64,7 @@ struct rchanstruct kref kref;/* channel refcount */ void *private_data;/* for user-defined data */ size_t last_toobig;/* tried to log event > subbuf size */ -struct rchan_buf *buf[NR_CPUS ];/* per-cpu channel buffers */ +struct rchan_buf **__percpu buf;/* per-cpu channel buffers */ int is_global;/* One global buffer ? */ struct list_head list;/* for channel list */ struct dentry *parent;/* parent dentry passed to open */
@@ -204,7 +205,7 @@ static inline void relay_write(struct rchan *chan,struct rchan_buf *buf;local_irq_save (flags); - buf = chan->buf[smp_processor_id ()]; + buf = *this_cpu_ptr (chan->buf);if (unlikely (buf->offset + length > chan->subbuf_size)) length =relay_switch_subbuf (buf, length);memcpy (buf->data + buf->offset, data, length);
@@ -230,12 +231,12 @@ static inline void __relay_write(struct rchan *chan, {struct rchan_buf *buf; - buf = chan->buf[get_cpu ()]; + buf = *get_cpu_ptr (chan->buf);if (unlikely (buf->offset + length > buf->chan->subbuf_size)) length =relay_switch_subbuf (buf, length);memcpy (buf->data + buf->offset, data, length); buf->offset += length; -put_cpu (); +put_cpu_ptr (chan->buf); }/**
@@ -251,17 +252,19 @@ static inline void __relay_write(struct rchan *chan,*/ static inline void *relay_reserve (struct rchan *chan,size_t length) { -void *reserved; -struct rchan_buf *buf = chan->buf[smp_processor_id ()]; +void *reserved =NULL ; +struct rchan_buf *buf = *get_cpu_ptr (chan->buf);if (unlikely (buf->offset + length > buf->chan->subbuf_size)) { length =relay_switch_subbuf (buf, length);if (!length) -return NULL ; + goto end; } reserved = buf->data + buf->offset; buf->offset += length; +end: +put_cpu_ptr (chan->buf);return reserved; }
kernel/relay.c +42 -32
222 lines not on this page · raw message
tip-bot for Akash Goel
merge botrelay: Use per CPU constructs for the relay channel buffer pointers
Commit-ID: 017c59c042d01fc84cae7a8ea475861e702c77ab Gitweb: http://git.kernel.org/tip/017c59c042d01fc84cae7a8ea475861e702c77ab Author: Akash Goel <[email protected]> AuthorDate: Fri, 2 Sep 2016 21:47:38 +0200 Committer: Thomas Gleixner <[email protected]> CommitDate: Tue, 6 Sep 2016 18:30:19 +0200
relay: Use per CPU constructs for the relay channel buffer pointers
relay essentially needs to maintain a per CPU array of channel buffer pointers but it manually creates that array. Instead its better to use the per CPU constructs, provided by the kernel, to allocate & access the array of pointer to channel buffers.
--- include/linux/relay.h | 17 +++++++----- kernel/relay.c | 74 +++++++++++++++++++++++++++++---------------------- 2 files changed, 52 insertions(+), 39 deletions(-)
include/linux/relay.h +10 -7
@@ -19,6 +19,7 @@#include <linux/fs.h> #include <linux/poll.h> #include <linux/kref.h> +#include <linux/percpu.h> /* * Tracks changes to rchan/rchan_buf structs
@@ -63,7 +64,7 @@ struct rchanstruct kref kref;/* channel refcount */ void *private_data;/* for user-defined data */ size_t last_toobig;/* tried to log event > subbuf size */ -struct rchan_buf *buf[NR_CPUS ];/* per-cpu channel buffers */ +struct rchan_buf **__percpu buf;/* per-cpu channel buffers */ int is_global;/* One global buffer ? */ struct list_head list;/* for channel list */ struct dentry *parent;/* parent dentry passed to open */
@@ -204,7 +205,7 @@ static inline void relay_write(struct rchan *chan,struct rchan_buf *buf;local_irq_save (flags); - buf = chan->buf[smp_processor_id ()]; + buf = *this_cpu_ptr (chan->buf);if (unlikely (buf->offset + length > chan->subbuf_size)) length =relay_switch_subbuf (buf, length);memcpy (buf->data + buf->offset, data, length);
@@ -230,12 +231,12 @@ static inline void __relay_write(struct rchan *chan, {struct rchan_buf *buf; - buf = chan->buf[get_cpu ()]; + buf = *get_cpu_ptr (chan->buf);if (unlikely (buf->offset + length > buf->chan->subbuf_size)) length =relay_switch_subbuf (buf, length);memcpy (buf->data + buf->offset, data, length); buf->offset += length; -put_cpu (); +put_cpu_ptr (chan->buf); }/**
@@ -251,17 +252,19 @@ static inline void __relay_write(struct rchan *chan,*/ static inline void *relay_reserve (struct rchan *chan,size_t length) { -void *reserved; -struct rchan_buf *buf = chan->buf[smp_processor_id ()]; +void *reserved =NULL ; +struct rchan_buf *buf = *get_cpu_ptr (chan->buf);if (unlikely (buf->offset + length > buf->chan->subbuf_size)) { length =relay_switch_subbuf (buf, length);if (!length) -return NULL ; + goto end; } reserved = buf->data + buf->offset; buf->offset += length; +end: +put_cpu_ptr (chan->buf);return reserved; }
kernel/relay.c +42 -32
222 lines not on this page · raw message