New per-cpu patch v2.5.1

New per-cpu patch v2.5.1

Post by Rusty Russel » Fri, 21 Dec 2001 15:20:08



After some discussion, this may be a more sane (untested) per-cpu area
patch.  It dynamically allocated the sections (and discards the
original), which would allow (future) NUMA people to make sure their
CPU area is allocated near them.

Comments welcome,
Rusty.
--
  Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.1/arch/i386/vmlinux.lds working-2.5.1-percpu/arch/i386/vmlinux.lds
--- linux-2.5.1/arch/i386/vmlinux.lds   Tue Jul  3 07:40:14 2001

   __initcall_start = .;
   .initcall.init : { *(.initcall.init) }
   __initcall_end = .;
+  . = ALIGN(32);
+  __per_cpu_start = .;
+  .data.percpu  : { *(.data.percpu) }
+  __per_cpu_end = .;
   . = ALIGN(4096);
   __init_end = .;

diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.1/arch/ppc/vmlinux.lds working-2.5.1-percpu/arch/ppc/vmlinux.lds
--- linux-2.5.1/arch/ppc/vmlinux.lds    Tue Aug 28 23:58:33 2001

   __initcall_start = .;
   .initcall.init : { *(.initcall.init) }
   __initcall_end = .;
+  . = ALIGN(32);
+  __per_cpu_start = .;
+  .data.percpu  : { *(.data.percpu) }
+  __per_cpu_end = .;
   . = ALIGN(4096);
   __init_end = .;

diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.1/include/linux/smp.h working-2.5.1-percpu/include/linux/smp.h
--- linux-2.5.1/include/linux/smp.h     Tue Dec 18 19:08:06 2001

 #define MSG_RESCHEDULE         0x0003  /* Reschedule request from master CPU*/
 #define MSG_CALL_FUNCTION       0x0004  /* Call function on all other CPUs */

-#else
+#define PER_CPU(decl)  decl##__percpu __attribute__((section(".data.percpu")))
+
+/* Created by linker magic */
+extern char __per_cpu_start, __per_cpu_end;
+
+extern void *per_cpu_off[NR_CPUS];
+
+#define per_cpu(var, cpu)                                      \
+(*(__typeof__(&var)((void *)&var##__percpu - &__per_cpu_start)     \
+   + per_cpu_off[cpu]))
+
+#else /* !SMP */

 /*

 #define cpu_number_map(cpu)                    0
 #define smp_call_function(func,info,retry,wait)        ({ 0; })
 #define cpu_online_map                         1
-
+#define PER_CPU(decl)                          decl
+#define per_cpu(var, cpu)                      var
 #endif
+
+#define this_cpu(var)                          per_cpu(var,smp_processor_id())
+
 #endif
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.1/init/main.c working-2.5.1-percpu/init/main.c
--- linux-2.5.1/init/main.c     Mon Dec 17 16:09:13 2001

 #else

+void *per_cpu_off[NR_CPUS];

 /* Called by boot processor to activate the rest. */
 static void __init smp_init(void)
 {
+       unsigned int i;
+       size_t per_cpu_size;
+
        /* Get other processors into their bootup holding patterns. */
        smp_boot_cpus();

                barrier();
        }
        printk("All processors have done init_idle\n");
+
+       /* Set up per-CPU section pointers.  Page align to be safe. */
+       per_cpu_size = ((&__per_cpu_end - &__per_cpu_start) + PAGE_SIZE-1)
+               & ~(PAGE_SIZE-1);
+       per_cpu_off[0] = kmalloc(per_cpu_size * smp_num_cpus, GFP_KERNEL);
+       for (i = 0; i < smp_num_cpus; i++) {
+               per_cpu_off[i] = per_cpu_off[0] + per_cpu_size;
+               memcpy(per_cpu_off[i], &__per_cpu_start,
+                      __per_cpu_end - &__per_cpu_start);
+       }
 }

 #endif
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

New per-cpu patch v2.5.1

Post by Robert Lov » Fri, 21 Dec 2001 15:30:10



> After some discussion, this may be a more sane (untested) per-cpu area
> patch.  It dynamically allocated the sections (and discards the
> original), which would allow (future) NUMA people to make sure their
> CPU area is allocated near them.

> Comments welcome,

Would the next step be to find the various per-CPU data in the kernel
and convert it to your new form?  I.e., is this a general purpose
interface for per-CPU data structures, or am I missing something?

If it is, this is a good idea.  Other Unices have this (IRIX comes to
mind).  One of the biggest advantages, IMO, is simply the readability --
data structures that are per-CPU have varying methods of creation and
referencing.  The implicit locking (i.e., none) can be unclear.

Bring everything together can be a good thing.

        Robert Love

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

1. per-cpu patch 1/3

Name: Export __per_cpu_offset so modules can use per-cpu data.
Author: Rusty Russell
Status: Trivial

D: As per Andrew Morton's request.

diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.25/kernel/ksyms.c working-2.5.25-percpu/kernel/ksyms.c
--- linux-2.5.25/kernel/ksyms.c Sun Jul  7 02:12:24 2002

 #include <linux/namei.h>
 #include <linux/buffer_head.h>
 #include <linux/root_dev.h>
+#include <linux/percpu.h>
 #include <asm/checksum.h>


 EXPORT_SYMBOL(tasklist_lock);
 EXPORT_SYMBOL(pidhash);
+#if defined(CONFIG_SMP) && defined(__GENERIC_PER_CPU)
+EXPORT_SYMBOL(__per_cpu_offset);
+#endif

--
  Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

2. load pcmcia driver?

3. Make prof_counter use per-cpu areas patch 1/4 -- x86 arch

4. IO-APIC in SMP dual Athlon XP1800

5. per-cpu patch 3/3

6. Network Time

7. New, shiny per-cpu macros...

8. Smooth animation & scheduling?

9. Only allocate per-cpu copies for possible CPUs

10. Q: gcc v2.8.0 on solaris v2.5.1

11. solaris x86 v2.5 vs. v2.5.1 performance

12. Limiting max cpu usage per user (old Conectiva patch)

13. Patching tru64 5.1/trucluster 5.1