Re: [guv v2 04/31] net: Replace __get_cpu_var uses
David Miller wrote: > > Would it be possible to use __thread annotations for per-CPU > > variables, I wonder? > > Paul Mackerras tried it on powerpc and you can't do it. > > The problem is that there is no way to tell the compiler that sched() > and similar (potentially) change the thread pointer base. > > It really will cache pre-computed __thread pointer calculations across > sched(). Yeah... I thought there might be something like that - but I could see x86_64 using %fs as a base. David -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [guv v2 04/31] net: Replace __get_cpu_var uses
On Mon, 2 Sep 2013, David Howells wrote: > Would it be possible to use __thread annotations for per-CPU variables, I > wonder? We already have a __percpu annotation. Looked at __thread a couple of years ago but found that support for the kernel segment register was not available. If we had __thread then most of the operations could simply be provided by the compiler. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [guv v2 04/31] net: Replace __get_cpu_var uses
On Mon, 2 Sep 2013, David Miller wrote: > It really will cache pre-computed __thread pointer calculations across > sched(). On x86 the compiler could use the segment prefix and then it may work. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [guv v2 04/31] net: Replace __get_cpu_var uses
On Mon, 2 Sep 2013, David Miller wrote: It really will cache pre-computed __thread pointer calculations across sched(). On x86 the compiler could use the segment prefix and then it may work. -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [guv v2 04/31] net: Replace __get_cpu_var uses
On Mon, 2 Sep 2013, David Howells wrote: Would it be possible to use __thread annotations for per-CPU variables, I wonder? We already have a __percpu annotation. Looked at __thread a couple of years ago but found that support for the kernel segment register was not available. If we had __thread then most of the operations could simply be provided by the compiler. -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [guv v2 04/31] net: Replace __get_cpu_var uses
David Miller da...@davemloft.net wrote: Would it be possible to use __thread annotations for per-CPU variables, I wonder? Paul Mackerras tried it on powerpc and you can't do it. The problem is that there is no way to tell the compiler that sched() and similar (potentially) change the thread pointer base. It really will cache pre-computed __thread pointer calculations across sched(). Yeah... I thought there might be something like that - but I could see x86_64 using %fs as a base. David -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [guv v2 04/31] net: Replace __get_cpu_var uses
From: David Howells Date: Mon, 02 Sep 2013 22:35:06 +0100 > Would it be possible to use __thread annotations for per-CPU > variables, I wonder? Paul Mackerras tried it on powerpc and you can't do it. The problem is that there is no way to tell the compiler that sched() and similar (potentially) change the thread pointer base. It really will cache pre-computed __thread pointer calculations across sched(). -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [guv v2 04/31] net: Replace __get_cpu_var uses
Would it be possible to use __thread annotations for per-CPU variables, I wonder? David -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [guv v2 04/31] net: Replace __get_cpu_var uses
Would it be possible to use __thread annotations for per-CPU variables, I wonder? David -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [guv v2 04/31] net: Replace __get_cpu_var uses
From: David Howells dhowe...@redhat.com Date: Mon, 02 Sep 2013 22:35:06 +0100 Would it be possible to use __thread annotations for per-CPU variables, I wonder? Paul Mackerras tried it on powerpc and you can't do it. The problem is that there is no way to tell the compiler that sched() and similar (potentially) change the thread pointer base. It really will cache pre-computed __thread pointer calculations across sched(). -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[guv v2 04/31] net: Replace __get_cpu_var uses
__get_cpu_var() is used for multiple purposes in the kernel source. One of them is address calculation via the form &__get_cpu_var(x). This calculates the address for the instance of the percpu variable of the current processor based on an offset. Others usage cases are for storing and retrieving data from the current processors percpu area. __get_cpu_var() can be used as an lvalue when writing data or on the right side of an assignment. __get_cpu_var() is defined as : #define __get_cpu_var(var) (*this_cpu_ptr(&(var))) __get_cpu_var() always only does a address determination. However, store and retrieve operations could use a segment prefix (or global register on other platforms) to avoid the address calculation. this_cpu_write() and this_cpu_read() can directly take an offset into a percpu area and use optimized assembly code to read and write per cpu variables. This patch converts __get_cpu_var into either and explicit address calculation using this_cpu_ptr() or into a use of this_cpu operations that use the offset. Thereby address calcualtions are avoided and less registers are used when code is generated. At the end of the patchset all uses of __get_cpu_var have been removed so the macro is removed too. The patchset includes passes over all arches as well. Once these operations are used throughout then specialized macros can be defined in non -x86 arches as well in order to optimize per cpu access by f.e. using a global register that may be set to the per cpu base. Transformations done to __get_cpu_var() 1. Determine the address of the percpu instance of the current processor. DEFINE_PER_CPU(int, y); int *x = &__get_cpu_var(y); Converts to int *x = this_cpu_ptr(); 2. Same as #1 but this time an array structure is involved. DEFINE_PER_CPU(int, y[20]); int *x = __get_cpu_var(y); Converts to int *x = this_cpu_ptr(y); 3. Retrieve the content of the current processors instance of a per cpu variable. DEFINE_PER_CPU(int, u); int x = __get_cpu_var(y) Converts to int x = __this_cpu_read(y); 4. Retrieve the content of a percpu struct DEFINE_PER_CPU(struct mystruct, y); struct mystruct x = __get_cpu_var(y); Converts to memcpy(this_cpu_ptr(), x, sizeof(x)); 5. Assignment to a per cpu variable DEFINE_PER_CPU(int, y) __get_cpu_var(y) = x; Converts to this_cpu_write(y, x); 6. Increment/Decrement etc of a per cpu variable DEFINE_PER_CPU(int, y); __get_cpu_var(y)++ Converts to this_cpu_inc(y) Signed-off-by: Christoph Lameter Index: linux/net/core/dev.c === --- linux.orig/net/core/dev.c 2013-08-26 14:16:59.0 -0500 +++ linux/net/core/dev.c2013-08-26 14:18:37.214005168 -0500 @@ -2129,7 +2129,7 @@ static inline void __netif_reschedule(st unsigned long flags; local_irq_save(flags); - sd = &__get_cpu_var(softnet_data); + sd = this_cpu_ptr(_data); q->next_sched = NULL; *sd->output_queue_tailp = q; sd->output_queue_tailp = >next_sched; @@ -2151,7 +2151,7 @@ void dev_kfree_skb_irq(struct sk_buff *s unsigned long flags; local_irq_save(flags); - sd = &__get_cpu_var(softnet_data); + sd = this_cpu_ptr(_data); skb->next = sd->completion_queue; sd->completion_queue = skb; raise_softirq_irqoff(NET_TX_SOFTIRQ); @@ -3111,7 +3111,7 @@ static void rps_trigger_softirq(void *da static int rps_ipi_queued(struct softnet_data *sd) { #ifdef CONFIG_RPS - struct softnet_data *mysd = &__get_cpu_var(softnet_data); + struct softnet_data *mysd = this_cpu_ptr(_data); if (sd != mysd) { sd->rps_ipi_next = mysd->rps_ipi_list; @@ -3138,7 +3138,7 @@ static bool skb_flow_limit(struct sk_buf if (qlen < (netdev_max_backlog >> 1)) return false; - sd = &__get_cpu_var(softnet_data); + sd = this_cpu_ptr(_data); rcu_read_lock(); fl = rcu_dereference(sd->flow_limit); @@ -3280,7 +3280,7 @@ EXPORT_SYMBOL(netif_rx_ni); static void net_tx_action(struct softirq_action *h) { - struct softnet_data *sd = &__get_cpu_var(softnet_data); + struct softnet_data *sd = this_cpu_ptr(_data); if (sd->completion_queue) { struct sk_buff *clist; @@ -3700,7 +3700,7 @@ EXPORT_SYMBOL(netif_receive_skb); static void flush_backlog(void *arg) { struct net_device *dev = arg; - struct softnet_data *sd = &__get_cpu_var(softnet_data); + struct softnet_data *sd = this_cpu_ptr(_data); struct sk_buff *skb, *tmp; rps_lock(sd); @@ -4146,7 +4146,7 @@ void __napi_schedule(struct napi_struct unsigned long flags; local_irq_save(flags); -
[guv v2 04/31] net: Replace __get_cpu_var uses
__get_cpu_var() is used for multiple purposes in the kernel source. One of them is address calculation via the form __get_cpu_var(x). This calculates the address for the instance of the percpu variable of the current processor based on an offset. Others usage cases are for storing and retrieving data from the current processors percpu area. __get_cpu_var() can be used as an lvalue when writing data or on the right side of an assignment. __get_cpu_var() is defined as : #define __get_cpu_var(var) (*this_cpu_ptr((var))) __get_cpu_var() always only does a address determination. However, store and retrieve operations could use a segment prefix (or global register on other platforms) to avoid the address calculation. this_cpu_write() and this_cpu_read() can directly take an offset into a percpu area and use optimized assembly code to read and write per cpu variables. This patch converts __get_cpu_var into either and explicit address calculation using this_cpu_ptr() or into a use of this_cpu operations that use the offset. Thereby address calcualtions are avoided and less registers are used when code is generated. At the end of the patchset all uses of __get_cpu_var have been removed so the macro is removed too. The patchset includes passes over all arches as well. Once these operations are used throughout then specialized macros can be defined in non -x86 arches as well in order to optimize per cpu access by f.e. using a global register that may be set to the per cpu base. Transformations done to __get_cpu_var() 1. Determine the address of the percpu instance of the current processor. DEFINE_PER_CPU(int, y); int *x = __get_cpu_var(y); Converts to int *x = this_cpu_ptr(y); 2. Same as #1 but this time an array structure is involved. DEFINE_PER_CPU(int, y[20]); int *x = __get_cpu_var(y); Converts to int *x = this_cpu_ptr(y); 3. Retrieve the content of the current processors instance of a per cpu variable. DEFINE_PER_CPU(int, u); int x = __get_cpu_var(y) Converts to int x = __this_cpu_read(y); 4. Retrieve the content of a percpu struct DEFINE_PER_CPU(struct mystruct, y); struct mystruct x = __get_cpu_var(y); Converts to memcpy(this_cpu_ptr(y), x, sizeof(x)); 5. Assignment to a per cpu variable DEFINE_PER_CPU(int, y) __get_cpu_var(y) = x; Converts to this_cpu_write(y, x); 6. Increment/Decrement etc of a per cpu variable DEFINE_PER_CPU(int, y); __get_cpu_var(y)++ Converts to this_cpu_inc(y) Signed-off-by: Christoph Lameter c...@linux.com Index: linux/net/core/dev.c === --- linux.orig/net/core/dev.c 2013-08-26 14:16:59.0 -0500 +++ linux/net/core/dev.c2013-08-26 14:18:37.214005168 -0500 @@ -2129,7 +2129,7 @@ static inline void __netif_reschedule(st unsigned long flags; local_irq_save(flags); - sd = __get_cpu_var(softnet_data); + sd = this_cpu_ptr(softnet_data); q-next_sched = NULL; *sd-output_queue_tailp = q; sd-output_queue_tailp = q-next_sched; @@ -2151,7 +2151,7 @@ void dev_kfree_skb_irq(struct sk_buff *s unsigned long flags; local_irq_save(flags); - sd = __get_cpu_var(softnet_data); + sd = this_cpu_ptr(softnet_data); skb-next = sd-completion_queue; sd-completion_queue = skb; raise_softirq_irqoff(NET_TX_SOFTIRQ); @@ -3111,7 +3111,7 @@ static void rps_trigger_softirq(void *da static int rps_ipi_queued(struct softnet_data *sd) { #ifdef CONFIG_RPS - struct softnet_data *mysd = __get_cpu_var(softnet_data); + struct softnet_data *mysd = this_cpu_ptr(softnet_data); if (sd != mysd) { sd-rps_ipi_next = mysd-rps_ipi_list; @@ -3138,7 +3138,7 @@ static bool skb_flow_limit(struct sk_buf if (qlen (netdev_max_backlog 1)) return false; - sd = __get_cpu_var(softnet_data); + sd = this_cpu_ptr(softnet_data); rcu_read_lock(); fl = rcu_dereference(sd-flow_limit); @@ -3280,7 +3280,7 @@ EXPORT_SYMBOL(netif_rx_ni); static void net_tx_action(struct softirq_action *h) { - struct softnet_data *sd = __get_cpu_var(softnet_data); + struct softnet_data *sd = this_cpu_ptr(softnet_data); if (sd-completion_queue) { struct sk_buff *clist; @@ -3700,7 +3700,7 @@ EXPORT_SYMBOL(netif_receive_skb); static void flush_backlog(void *arg) { struct net_device *dev = arg; - struct softnet_data *sd = __get_cpu_var(softnet_data); + struct softnet_data *sd = this_cpu_ptr(softnet_data); struct sk_buff *skb, *tmp; rps_lock(sd); @@ -4146,7 +4146,7 @@ void __napi_schedule(struct napi_struct unsigned long flags;