Skip to contentSkip to conversation

[PATCCH percpu: add cpunum param in per_cpu_ptr_to_phys

PATCH Dave Young 3 participants 4 messages Nov 15, 2011 – Nov 16, 2011

Subsystems (3)
lore
Share & tools
lore

Dave Young

author
#0 lore raw

per_cpu_ptr_to_phys iterate all cpu to get the phy addr let's leave the caller to pass the cpu number to it.

Actually in the only one user show_crash_notes,
cpunum is provided already before calling this.

---
 drivers/base/cpu.c     |    2 +-
 include/linux/percpu.h |    2 +-
 mm/percpu.c            |   29 ++++-------------------------
 3 files changed, 6 insertions(+), 27 deletions(-)
drivers/base/cpu.c +1 -1
@@ -125,7 +125,7 @@ static ssize_t show_crash_notes(struct s
 	 * boot up and this data does not change there after. Hence this
 	 * operation should be safe. No locking required.
 	 */
-	addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpunum));
+	addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpunum), cpunum);
 	rc = sprintf(buf, "%Lx\n", addr);
 	return rc;
 }
include/linux/percpu.h +1 -1
@@ -160,7 +160,7 @@ extern void __init percpu_init_late(void
 
 extern void __percpu *__alloc_percpu(size_t size, size_t align);
 extern void free_percpu(void __percpu *__pdata);
-extern phys_addr_t per_cpu_ptr_to_phys(void *addr);
+extern phys_addr_t per_cpu_ptr_to_phys(void *addr, int cpunum);
 
 #define alloc_percpu(type)	\
 	(typeof(type) __percpu *)__alloc_percpu(sizeof(type), __alignof__(type))
mm/percpu.c +4 -25
@@ -971,6 +971,7 @@ bool is_kernel_percpu_address(unsigned l
 /**
  * per_cpu_ptr_to_phys - convert translated percpu address to physical address
  * @addr: the address to be converted to physical address
+ * @cpunum: the cpu number of percpu address
  *
  * Given @addr which is dereferenceable address obtained via one of
  * percpu access macros, this function translates it into its physical
@@ -980,34 +981,12 @@ bool is_kernel_percpu_address(unsigned l
  * RETURNS:
  * The physical address for @addr.
  */
-phys_addr_t per_cpu_ptr_to_phys(void *addr)
+phys_addr_t per_cpu_ptr_to_phys(void *addr, int cpunum)
 {
 	void __percpu *base = __addr_to_pcpu_ptr(pcpu_base_addr);
-	bool in_first_chunk = false;
-	unsigned long first_start, first_end;
-	unsigned int cpu;
+	void *start = per_cpu_ptr(base, cpunum);
 
-	/*
-	 * The following test on first_start/end isn't strictly
-	 * necessary but will speed up lookups of addresses which
-	 * aren't in the first chunk.
-	 */
-	first_start = pcpu_chunk_addr(pcpu_first_chunk, pcpu_first_unit_cpu, 0);
-	first_end = pcpu_chunk_addr(pcpu_first_chunk, pcpu_last_unit_cpu,
-				    pcpu_unit_pages);
-	if ((unsigned long)addr >= first_start &&
-	    (unsigned long)addr < first_end) {
-		for_each_possible_cpu(cpu) {
-			void *start = per_cpu_ptr(base, cpu);
-
-			if (addr >= start && addr < start + pcpu_unit_size) {
-				in_first_chunk = true;
-				break;
-			}
-		}
-	}
-
-	if (in_first_chunk) {
+	if (addr >= start && addr < start + pcpu_unit_size) {
 		if (!is_vmalloc_addr(addr))
 			return __pa(addr);
 		else

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#1 lore raw
Quoted 7 lines · Dave Young

per_cpu_ptr_to_phys iterate all cpu to get the phy addr let's leave the caller to pass the cpu number to it.

Actually in the only one user show_crash_notes,
cpunum is provided already before calling this.

Does this matter? If it's not a performance critical path, I'd rather keep the generic funtionality.

Thanks.

Signature · 1 line
tejun
#2 lore raw
Quoted 11 lines · Tejun Heo
Quoted 7 lines · Dave Young

per_cpu_ptr_to_phys iterate all cpu to get the phy addr let's leave the caller to pass the cpu number to it.

Actually in the only one user show_crash_notes,
cpunum is provided already before calling this.

Does this matter?  If it's not a performance critical path, I'd rather keep the generic funtionality.

Hi, why not? the code is redundant, it's an improvement of the code, isn't it? Also, kernel code size will be smaller.

Quoted 13 lines

Thanks.

--
tejun

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Signature · 9 lines
Regards
Dave

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#3 lore raw

Hello,

Quoted 5 lines · Dave Young
Quoted 2 lines

Does this matter?  If it's not a performance critical path, I'd rather keep the generic funtionality.

Hi, why not? the code is redundant, it's an improvement of the code, isn't it? Also, kernel code size will be smaller.

(scratching head...) Ummm... I'm not sure whether it's an improvement or not. The contest is between loss of currently unused functionality and meaningless optimization. I vote for status quo.

Thanks.

Signature · 8 lines
tejun

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>