From: John L. <mov...@us...> - 2001-09-21 08:29:13
|
Update of /cvsroot/oprofile/oprofile In directory usw-pr-cvs1:/tmp/cvs-serv22548 Modified Files: ChangeLog configure.in oprofile.c oprofile.h Log Message: likely/unlikely support. needs fixing and testing with pre13 Index: ChangeLog =================================================================== RCS file: /cvsroot/oprofile/oprofile/ChangeLog,v retrieving revision 1.128 retrieving revision 1.129 diff -u -d -r1.128 -r1.129 --- ChangeLog 2001/09/21 06:33:17 1.128 +++ ChangeLog 2001/09/21 08:29:10 1.129 @@ -1,3 +1,11 @@ +2001-09-21 John Levon <mo...@co...> + + * dae/opd_proc.c: removed over-verbose line + + * configure.in: + * oprofile.h: + * oprofile.c: add likely/unlikely, take note lock on dump + 2001-09-21 Philippe Elie <ph...@cl...> * pp/opf_filter.h: move declaration of counter_array_t to Index: configure.in =================================================================== RCS file: /cvsroot/oprofile/oprofile/configure.in,v retrieving revision 1.32 retrieving revision 1.33 diff -u -d -r1.32 -r1.33 --- configure.in 2001/09/18 01:00:33 1.32 +++ configure.in 2001/09/21 08:29:10 1.33 @@ -91,6 +91,19 @@ void monkey() __attribute__((malloc)); ],AC_MSG_RESULT("yes"); CFLAGS="$SAVE_CFLAGS -DMALLOC_OK", AC_MSG_RESULT("no"); CFLAGS="$SAVE_CFLAGS") +# FIXME !!!!!!!! +# AC_MSG_CHECKING("whether __builtin_expect is understood") +# SAVE_CFLAGS=$CFLAGS +# CFLAGS="-Werror $CFLAGS" +# AC_TRY_COMPILE(,[ +# int main() { +# int i; +# if (__builtin_expect(i, 0)) { +# } +# } +# ],AC_MSG_RESULT("yes"); BKCFLAGS="$BKCFLAGS -DEXPECT_OK", AC_MSG_RESULT("no");) +# CFLAGS=$SAVE_CFLAGS + AC_MSG_CHECKING(for x86 architecture) AX_COMPILE_OPTION(CONFIG_X86,x86=1,x86=0) Index: oprofile.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/oprofile.c,v retrieving revision 1.91 retrieving revision 1.92 diff -u -d -r1.91 -r1.92 --- oprofile.c 2001/09/19 20:08:21 1.91 +++ oprofile.c 2001/09/21 08:29:10 1.92 @@ -74,13 +74,15 @@ /* FIXME: this whole handler would probably be better in straight asm */ static void evict_op_entry(struct _oprof_data *data, struct op_sample *ops) { + uint cpu = op_cpu_id(); + memcpy(&data->buffer[data->nextbuf], ops, sizeof(struct op_sample)); - if (++data->nextbuf != (data->buf_size - OP_PRE_WATERMARK)) { + if (likely(++data->nextbuf != (data->buf_size - OP_PRE_WATERMARK))) { if (data->nextbuf == data->buf_size) data->nextbuf = 0; return; } - oprof_ready[op_cpu_id()] = 1; + oprof_ready[cpu] = 1; } inline static void fill_op_entry(struct op_sample *ops, struct pt_regs *regs, int ctr) @@ -100,9 +102,9 @@ data->entries[h].samples[i].count++; set_perfctr(data->ctr_count[ctr], ctr); return; - } else if (op_full_count(data->entries[h].samples[i].count)) { + } else if (unlikely(op_full_count(data->entries[h].samples[i].count))) { goto full_entry; - } else if (!data->entries[h].samples[i].count) + } else if (unlikely(!data->entries[h].samples[i].count)) goto new_entry; } @@ -134,9 +136,9 @@ struct _oprof_data *data = &oprof_data[op_cpu_id()]; int i; - if (pid_filter && current->pid != pid_filter) + if (unlikely(pid_filter) && likely(current->pid != pid_filter)) return; - if (pgrp_filter && current->pgrp != pgrp_filter) + if (unlikely(pgrp_filter) && likely(current->pgrp != pgrp_filter)) return; for (i = 0 ; i < op_nr_counters ; ++i) { @@ -843,7 +845,6 @@ int i,j; down(&sysctlsem); - if (!prof_on) goto out; @@ -858,6 +859,7 @@ /* clean out the hash table as far as possible */ for (cpu=0; cpu < smp_num_cpus; cpu++) { struct _oprof_data * data = &oprof_data[cpu]; + spin_lock(¬e_lock); pmc_select_stop(cpu); for (i=0; i < data->hash_size; i++) { for (j=0; j < OP_NR_ENTRY; j++) @@ -865,6 +867,7 @@ if (oprof_ready[cpu]) break; } + spin_unlock(¬e_lock); oprof_ready[cpu] = 2; pmc_select_start(cpu); } Index: oprofile.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/oprofile.h,v retrieving revision 1.54 retrieving revision 1.55 diff -u -d -r1.54 -r1.55 --- oprofile.h 2001/09/18 10:00:07 1.54 +++ oprofile.h 2001/09/21 08:29:10 1.55 @@ -174,6 +174,22 @@ #define op_cpu_id() (cpu_number_map(smp_processor_id())) +/* branch prediction */ +#ifdef EXPECT_OK +#ifndef likely +#define likely(a) __builtin_expect((a), 1) +#endif +#ifndef unlikely +#define unlikely(a) __builtin_expect((a), 0) +#endif +#else +#ifdef likely +#error likely defined - kernel compiler and compiler specified do not match ! +#endif +#define likely(a) (a) +#define unlikely(a) (a) +#endif + /* we can't unload safely on SMP */ #ifdef CONFIG_SMP #define smp_can_unload() (allow_unload) |