Hi,In testing the latest libpfm (containing the patch which adds PCL event codes for Power), I ran into a blunder I had made. The switch statement in pfm_gen_powerpc_get_event_code was missing return statements in each of the cases. I have fixed this error, and have improved the code by adding correct pfmlib error codes and also validated that the event number is within range for each Power PMU type.
I've attached a patch which contains a changelog. Please let me know if there are problems with it.
Thanks for your consideration, - Corey Corey Ashford Software Engineer IBM Linux Technology Center, Linux Toolchain Beaverton, OR 503-578-3507 cjash...@us.ibm.com
This does two things: corrects a switch statement in pfm_gen_powerpc_get_event_code() that was missing returns for each case, and also improves the code by returning correct pfmlib error codes and checks for a valid event number. This has been tested on Power5 using PAPI as a driver. Signed off by: Corey Ashford <cjash...@us.ibm.com>` Index: libpfm/lib/pfmlib_gen_powerpc.c =================================================================== --- libpfm.orig/lib/pfmlib_gen_powerpc.c 2009-06-16 17:51:07.000000000 -0700 +++ libpfm/lib/pfmlib_gen_powerpc.c 2009-06-16 18:07:39.000000000 -0700 @@ -237,21 +237,44 @@ { switch (gen_powerpc_support.pmu_type) { case PFMLIB_PPC970_PMU: - *code = ppc970_pe[event].pme_code; + if (event < PPC970_PME_EVENT_COUNT) { + *code = ppc970_pe[event].pme_code; + return PFMLIB_SUCCESS; + } else + return PFMLIB_ERR_INVAL; case PFMLIB_PPC970MP_PMU: - *code = ppc970mp_pe[event].pme_code; + if (event < PPC970MP_PME_EVENT_COUNT) { + *code = ppc970mp_pe[event].pme_code; + return PFMLIB_SUCCESS; + } else + return PFMLIB_ERR_INVAL; case PFMLIB_POWER4_PMU: - *code = power4_pe[event].pme_code; + if (event < POWER4_PME_EVENT_COUNT) { + *code = power4_pe[event].pme_code; + return PFMLIB_SUCCESS; + } else + return PFMLIB_ERR_INVAL; case PFMLIB_POWER5_PMU: - *code = power5_pe[event].pme_code; + if (event < POWER5_PME_EVENT_COUNT) { + *code = power5_pe[event].pme_code; + return PFMLIB_SUCCESS; + } else + return PFMLIB_ERR_INVAL; case PFMLIB_POWER5p_PMU: - *code = power5p_pe[event].pme_code; + if (event < POWER5p_PME_EVENT_COUNT) { + *code = power5p_pe[event].pme_code; + return PFMLIB_SUCCESS; + } else + return PFMLIB_ERR_INVAL; case PFMLIB_POWER6_PMU: - *code = power6_pe[event].pme_code; + if (event < POWER6_PME_EVENT_COUNT) { + *code = power6_pe[event].pme_code; + return PFMLIB_SUCCESS; + } else + return PFMLIB_ERR_INVAL; default: - return -1; + return PFMLIB_ERR_BADHOST; } - return 0; } /**
------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects
_______________________________________________ perfmon2-devel mailing list perfmon2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/perfmon2-devel