1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright (c) 2019, Joyent, Inc.
14 */
15
16 /*
17 * This program transforms Intel perfmon and AMD PMC data files into C files and
18 * manual pages.
19 */
20
21 #include <stdio.h>
22 #include <stdarg.h>
23 #include <unistd.h>
24 #include <err.h>
25 #include <libgen.h>
26 #include <libnvpair.h>
27 #include <strings.h>
28 #include <errno.h>
29 #include <limits.h>
30 #include <sys/mman.h>
31 #include <sys/param.h>
32 #include <assert.h>
33 #include <ctype.h>
402
403 /*
404 * Tokeninze the string. There may be an optional stepping portion,
405 * which has a range of steppings enclosed by '[' and ']' characters.
406 * While the other parts are required, the stepping may be missing.
407 */
408 if ((brand = strtok_r(fsr, "-", &last)) == NULL ||
409 (fam = strtok_r(NULL, "-", &last)) == NULL ||
410 (mod = strtok_r(NULL, "-", &last)) == NULL) {
411 errx(EXIT_FAILURE, "failed to parse processor id \"%s\"", fsr);
412 }
413 step = strtok_r(NULL, "-", &last);
414
415 if (strcmp(bstr, brand) != 0) {
416 errx(EXIT_FAILURE, "brand string \"%s\" did not match \"%s\"",
417 brand, bstr);
418 }
419
420 errno = 0;
421 l = strtol(fam, &last, 16);
422 if (errno != 0 || l < 0 || l > UINT_MAX || *last != '\0') {
423 errx(EXIT_FAILURE, "failed to parse family \"%s\"", fam);
424 }
425 *family = (uint_t)l;
426
427 l = strtol(mod, &last, 16);
428 if (errno != 0 || l < 0 || l > UINT_MAX || *last != '\0') {
429 errx(EXIT_FAILURE, "failed to parse model \"%s\"", mod);
430 }
431 *model = (uint_t)l;
432
433 if (step == NULL) {
434 *nstepp = 0;
435 return;
436 }
437
438 if (*step != '[' || ((last = strrchr(step, ']')) == NULL)) {
439 errx(EXIT_FAILURE, "failed to parse stepping \"%s\": missing "
440 "stepping range brackets", step);
441 }
442 step++;
443 *last = '\0';
444 while (*step != '\0') {
445 if (!isxdigit(*step)) {
446 errx(EXIT_FAILURE, "failed to parse stepping: invalid "
447 "stepping identifier '0x%x'", *step);
448 }
875 map->cmap_name);
876 return (B_FALSE);
877 }
878 }
879 } else {
880 if (fprintf(f, ".It\n.Sy Family 0x%x, Model 0x%x\n",
881 proc->cproc_family, proc->cproc_model) == -1) {
882 warn("failed to write out model information "
883 "for %s", map->cmap_name);
884 return (B_FALSE);
885 }
886 }
887 }
888
889 if (fprintf(f, cpcgen_manual_intel_data) == -1) {
890 warn("failed to write out manual header for %s",
891 map->cmap_name);
892 return (B_FALSE);
893 }
894
895 free(upper);
896 return (B_TRUE);
897 }
898
899 static boolean_t
900 cpcgen_manual_intel_file_after(FILE *f, cpc_map_t *map)
901 {
902 if (fprintf(f, cpcgen_manual_intel_trailer) == -1) {
903 warn("failed to write out manual header for %s",
904 map->cmap_name);
905 return (B_FALSE);
906 }
907
908 return (B_TRUE);
909 }
910
911 static boolean_t
912 cpcgen_manual_intel_event(FILE *f, nvlist_t *nvl, const char *path,
913 uint32_t ent)
914 {
915 char *event, *lname, *brief = NULL, *public = NULL, *errata = NULL;
|
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright 2019, Joyent, Inc.
14 */
15
16 /*
17 * This program transforms Intel perfmon and AMD PMC data files into C files and
18 * manual pages.
19 */
20
21 #include <stdio.h>
22 #include <stdarg.h>
23 #include <unistd.h>
24 #include <err.h>
25 #include <libgen.h>
26 #include <libnvpair.h>
27 #include <strings.h>
28 #include <errno.h>
29 #include <limits.h>
30 #include <sys/mman.h>
31 #include <sys/param.h>
32 #include <assert.h>
33 #include <ctype.h>
402
403 /*
404 * Tokeninze the string. There may be an optional stepping portion,
405 * which has a range of steppings enclosed by '[' and ']' characters.
406 * While the other parts are required, the stepping may be missing.
407 */
408 if ((brand = strtok_r(fsr, "-", &last)) == NULL ||
409 (fam = strtok_r(NULL, "-", &last)) == NULL ||
410 (mod = strtok_r(NULL, "-", &last)) == NULL) {
411 errx(EXIT_FAILURE, "failed to parse processor id \"%s\"", fsr);
412 }
413 step = strtok_r(NULL, "-", &last);
414
415 if (strcmp(bstr, brand) != 0) {
416 errx(EXIT_FAILURE, "brand string \"%s\" did not match \"%s\"",
417 brand, bstr);
418 }
419
420 errno = 0;
421 l = strtol(fam, &last, 16);
422 if (errno != 0 || l < 0 || l >= INT_MAX || *last != '\0') {
423 errx(EXIT_FAILURE, "failed to parse family \"%s\"", fam);
424 }
425 *family = (uint_t)l;
426
427 l = strtol(mod, &last, 16);
428 if (errno != 0 || l < 0 || l >= INT_MAX || *last != '\0') {
429 errx(EXIT_FAILURE, "failed to parse model \"%s\"", mod);
430 }
431 *model = (uint_t)l;
432
433 if (step == NULL) {
434 *nstepp = 0;
435 return;
436 }
437
438 if (*step != '[' || ((last = strrchr(step, ']')) == NULL)) {
439 errx(EXIT_FAILURE, "failed to parse stepping \"%s\": missing "
440 "stepping range brackets", step);
441 }
442 step++;
443 *last = '\0';
444 while (*step != '\0') {
445 if (!isxdigit(*step)) {
446 errx(EXIT_FAILURE, "failed to parse stepping: invalid "
447 "stepping identifier '0x%x'", *step);
448 }
875 map->cmap_name);
876 return (B_FALSE);
877 }
878 }
879 } else {
880 if (fprintf(f, ".It\n.Sy Family 0x%x, Model 0x%x\n",
881 proc->cproc_family, proc->cproc_model) == -1) {
882 warn("failed to write out model information "
883 "for %s", map->cmap_name);
884 return (B_FALSE);
885 }
886 }
887 }
888
889 if (fprintf(f, cpcgen_manual_intel_data) == -1) {
890 warn("failed to write out manual header for %s",
891 map->cmap_name);
892 return (B_FALSE);
893 }
894
895 return (B_TRUE);
896 }
897
898 static boolean_t
899 cpcgen_manual_intel_file_after(FILE *f, cpc_map_t *map)
900 {
901 if (fprintf(f, cpcgen_manual_intel_trailer) == -1) {
902 warn("failed to write out manual header for %s",
903 map->cmap_name);
904 return (B_FALSE);
905 }
906
907 return (B_TRUE);
908 }
909
910 static boolean_t
911 cpcgen_manual_intel_event(FILE *f, nvlist_t *nvl, const char *path,
912 uint32_t ent)
913 {
914 char *event, *lname, *brief = NULL, *public = NULL, *errata = NULL;
|