From owner-svn-src-all@FreeBSD.ORG Tue May 19 18:58:20 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 140B96A6; Tue, 19 May 2015 18:58:20 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E76A2166E; Tue, 19 May 2015 18:58:19 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t4JIwJQt016664; Tue, 19 May 2015 18:58:19 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t4JIwJft016661; Tue, 19 May 2015 18:58:19 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201505191858.t4JIwJft016661@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Tue, 19 May 2015 18:58:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r283120 - in head: lib/libpmc sys/dev/hwpmc sys/sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 May 2015 18:58:20 -0000 Author: jhb Date: Tue May 19 18:58:18 2015 New Revision: 283120 URL: https://svnweb.freebsd.org/changeset/base/283120 Log: Use fixed enum values for PMC_CLASSES(). This removes one of the frequent causes of ABI breakage when new CPU types are added to hwpmc(4). Differential Revision: https://reviews.freebsd.org/D2586 Reviewed by: davide, emaste, gnn (earlier version) MFC after: 2 weeks Modified: head/lib/libpmc/libpmc.c head/sys/dev/hwpmc/hwpmc_mod.c head/sys/sys/pmc.h Modified: head/lib/libpmc/libpmc.c ============================================================================== --- head/lib/libpmc/libpmc.c Tue May 19 18:35:18 2015 (r283119) +++ head/lib/libpmc/libpmc.c Tue May 19 18:58:18 2015 (r283120) @@ -423,9 +423,14 @@ static const char * pmc_capability_names __PMC_CAPS() }; -static const char * pmc_class_names[] = { +struct pmc_class_map { + enum pmc_class pm_class; + const char *pm_name; +}; + +static const struct pmc_class_map pmc_class_names[] = { #undef __PMC_CLASS -#define __PMC_CLASS(C) #C , +#define __PMC_CLASS(S,V,D) { .pm_class = PMC_CLASS_##S, .pm_name = #S } , __PMC_CLASSES() }; @@ -3362,9 +3367,11 @@ pmc_name_of_capability(enum pmc_caps cap const char * pmc_name_of_class(enum pmc_class pc) { - if ((int) pc >= PMC_CLASS_FIRST && - pc <= PMC_CLASS_LAST) - return (pmc_class_names[pc]); + size_t n; + + for (n = 0; n < PMC_TABLE_SIZE(pmc_class_names); n++) + if (pc == pmc_class_names[n].pm_class) + return (pmc_class_names[n].pm_name); errno = EINVAL; return (NULL); Modified: head/sys/dev/hwpmc/hwpmc_mod.c ============================================================================== --- head/sys/dev/hwpmc/hwpmc_mod.c Tue May 19 18:35:18 2015 (r283119) +++ head/sys/dev/hwpmc/hwpmc_mod.c Tue May 19 18:58:18 2015 (r283120) @@ -4625,12 +4625,20 @@ pmc_kld_unload(void *arg __unused, const /* * initialization */ +static const char * +pmc_name_of_pmcclass(enum pmc_class class) +{ -static const char *pmc_name_of_pmcclass[] = { + switch (class) { #undef __PMC_CLASS -#define __PMC_CLASS(N) #N , - __PMC_CLASSES() -}; +#define __PMC_CLASS(S,V,D) \ + case PMC_CLASS_##S: \ + return #S; + __PMC_CLASSES(); + default: + return (""); + } +} /* * Base class initializer: allocate structure and set default classes. @@ -4909,7 +4917,7 @@ pmc_initialize(void) for (n = 0; n < (int) md->pmd_nclass; n++) { pcd = &md->pmd_classdep[n]; printf(" %s/%d/%d/0x%b", - pmc_name_of_pmcclass[pcd->pcd_class], + pmc_name_of_pmcclass(pcd->pcd_class), pcd->pcd_num, pcd->pcd_width, pcd->pcd_caps, Modified: head/sys/sys/pmc.h ============================================================================== --- head/sys/sys/pmc.h Tue May 19 18:35:18 2015 (r283119) +++ head/sys/sys/pmc.h Tue May 19 18:58:18 2015 (r283120) @@ -123,30 +123,30 @@ enum pmc_cputype { */ #define __PMC_CLASSES() \ - __PMC_CLASS(TSC) /* CPU Timestamp counter */ \ - __PMC_CLASS(K7) /* AMD K7 performance counters */ \ - __PMC_CLASS(K8) /* AMD K8 performance counters */ \ - __PMC_CLASS(P5) /* Intel Pentium counters */ \ - __PMC_CLASS(P6) /* Intel Pentium Pro counters */ \ - __PMC_CLASS(P4) /* Intel Pentium-IV counters */ \ - __PMC_CLASS(IAF) /* Intel Core2/Atom, fixed function */ \ - __PMC_CLASS(IAP) /* Intel Core...Atom, programmable */ \ - __PMC_CLASS(UCF) /* Intel Uncore fixed function */ \ - __PMC_CLASS(UCP) /* Intel Uncore programmable */ \ - __PMC_CLASS(XSCALE) /* Intel XScale counters */ \ - __PMC_CLASS(ARMV7) /* ARMv7 */ \ - __PMC_CLASS(ARMV8) /* ARMv8 */ \ - __PMC_CLASS(MIPS24K) /* MIPS 24K */ \ - __PMC_CLASS(OCTEON) /* Cavium Octeon */ \ - __PMC_CLASS(MIPS74K) /* MIPS 74K */ \ - __PMC_CLASS(PPC7450) /* Motorola MPC7450 class */ \ - __PMC_CLASS(PPC970) /* IBM PowerPC 970 class */ \ - __PMC_CLASS(E500) /* Freescale e500 class */ \ - __PMC_CLASS(SOFT) /* Software events */ + __PMC_CLASS(TSC, 0x000, "CPU Timestamp counter") \ + __PMC_CLASS(K7, 0x100, "AMD K7 performance counters") \ + __PMC_CLASS(K8, 0x101, "AMD K8 performance counters") \ + __PMC_CLASS(P5, 0x102, "Intel Pentium counters") \ + __PMC_CLASS(P6, 0x103, "Intel Pentium Pro counters") \ + __PMC_CLASS(P4, 0x104, "Intel Pentium-IV counters") \ + __PMC_CLASS(IAF, 0x105, "Intel Core2/Atom, fixed function") \ + __PMC_CLASS(IAP, 0x106, "Intel Core...Atom, programmable") \ + __PMC_CLASS(UCF, 0x107, "Intel Uncore fixed function") \ + __PMC_CLASS(UCP, 0x108, "Intel Uncore programmable") \ + __PMC_CLASS(XSCALE, 0x200, "Intel XScale counters") \ + __PMC_CLASS(ARMV7, 0x201, "ARMv7") \ + __PMC_CLASS(ARMV8, 0x202, "ARMv8") \ + __PMC_CLASS(MIPS24K, 0x300, "MIPS 24K") \ + __PMC_CLASS(OCTEON, 0x301, "Cavium Octeon") \ + __PMC_CLASS(MIPS74K, 0x302, "MIPS 74K") \ + __PMC_CLASS(PPC7450, 0x400, "Motorola MPC7450 class") \ + __PMC_CLASS(PPC970, 0x401, "IBM PowerPC 970 class") \ + __PMC_CLASS(E500, 0x402, "Freescale e500 class") \ + __PMC_CLASS(SOFT, 0x8000, "Software events") enum pmc_class { #undef __PMC_CLASS -#define __PMC_CLASS(N) PMC_CLASS_##N , +#define __PMC_CLASS(S,V,D) PMC_CLASS_##S = V, __PMC_CLASSES() };