Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/arch/x86/intel_sdsi: Add current meter support

Add support to read the 'meter_current' file. The display is the same as
the 'meter_certificate', but will show the current snapshot of the
counters.

Signed-off-by: David E. Box <david.e.box@linux.intel.com>
Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20240411025856.2782476-10-david.e.box@linux.intel.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>

authored by

David E. Box and committed by
Hans de Goede
f2464458 53310fe9

+30 -19
+30 -19
tools/arch/x86/intel_sdsi/intel_sdsi.c
··· 185 185 enum command { 186 186 CMD_SOCKET_INFO, 187 187 CMD_METER_CERT, 188 + CMD_METER_CURRENT_CERT, 188 189 CMD_STATE_CERT, 189 190 CMD_PROV_AKC, 190 191 CMD_PROV_CAP, ··· 334 333 feature[0] = name[3]; 335 334 } 336 335 337 - static int sdsi_meter_cert_show(struct sdsi_dev *s) 336 + static int sdsi_meter_cert_show(struct sdsi_dev *s, bool show_current) 338 337 { 339 338 char buf[METER_CERT_MAX_SIZE] = {0}; 340 339 struct bundle_encoding_counter *bec; 341 340 struct meter_certificate *mc; 342 341 uint32_t count = 0; 343 342 FILE *cert_ptr; 343 + char *cert_fname; 344 344 int ret, size; 345 345 char name[FEAT_LEN]; 346 346 ··· 351 349 352 350 if (!s->regs.en_features.sdsi) { 353 351 fprintf(stderr, "SDSi feature is present but not enabled.\n"); 354 - fprintf(stderr, " Unable to read meter certificate\n"); 355 352 return -1; 356 353 } 357 354 ··· 365 364 return ret; 366 365 } 367 366 368 - cert_ptr = fopen("meter_certificate", "r"); 367 + cert_fname = show_current ? "meter_current" : "meter_certificate"; 368 + cert_ptr = fopen(cert_fname, "r"); 369 + 369 370 if (!cert_ptr) { 370 - perror("Could not open 'meter_certificate' file"); 371 + fprintf(stderr, "Could not open '%s' file: %s", cert_fname, strerror(errno)); 371 372 return -1; 372 373 } 373 374 374 375 size = fread(buf, 1, sizeof(buf), cert_ptr); 375 376 if (!size) { 376 - fprintf(stderr, "Could not read 'meter_certificate' file\n"); 377 + fprintf(stderr, "Could not read '%s' file\n", cert_fname); 377 378 fclose(cert_ptr); 378 379 return -1; 379 380 } ··· 741 738 742 739 static void usage(char *prog) 743 740 { 744 - printf("Usage: %s [-l] [-d DEVNO [-i] [-s] [-m] [-a FILE] [-c FILE]]\n", prog); 741 + printf("Usage: %s [-l] [-d DEVNO [-i] [-s] [-m | -C] [-a FILE] [-c FILE]\n", prog); 745 742 } 746 743 747 744 static void show_help(void) ··· 750 747 printf(" %-18s\t%s\n", "-l, --list", "list available On Demand devices"); 751 748 printf(" %-18s\t%s\n", "-d, --devno DEVNO", "On Demand device number"); 752 749 printf(" %-18s\t%s\n", "-i, --info", "show socket information"); 753 - printf(" %-18s\t%s\n", "-s, --state", "show state certificate"); 754 - printf(" %-18s\t%s\n", "-m, --meter", "show meter certificate"); 750 + printf(" %-18s\t%s\n", "-s, --state", "show state certificate data"); 751 + printf(" %-18s\t%s\n", "-m, --meter", "show meter certificate data"); 752 + printf(" %-18s\t%s\n", "-C, --meter_current", "show live unattested meter data"); 755 753 printf(" %-18s\t%s\n", "-a, --akc FILE", "provision socket with AKC FILE"); 756 754 printf(" %-18s\t%s\n", "-c, --cap FILE>", "provision socket with CAP FILE"); 757 755 } ··· 768 764 int option_index = 0; 769 765 770 766 static struct option long_options[] = { 771 - {"akc", required_argument, 0, 'a'}, 772 - {"cap", required_argument, 0, 'c'}, 773 - {"devno", required_argument, 0, 'd'}, 774 - {"help", no_argument, 0, 'h'}, 775 - {"info", no_argument, 0, 'i'}, 776 - {"list", no_argument, 0, 'l'}, 777 - {"meter", no_argument, 0, 'm'}, 778 - {"state", no_argument, 0, 's'}, 779 - {0, 0, 0, 0 } 767 + {"akc", required_argument, 0, 'a'}, 768 + {"cap", required_argument, 0, 'c'}, 769 + {"devno", required_argument, 0, 'd'}, 770 + {"help", no_argument, 0, 'h'}, 771 + {"info", no_argument, 0, 'i'}, 772 + {"list", no_argument, 0, 'l'}, 773 + {"meter", no_argument, 0, 'm'}, 774 + {"meter_current", no_argument, 0, 'C'}, 775 + {"state", no_argument, 0, 's'}, 776 + {0, 0, 0, 0 } 780 777 }; 781 778 782 779 783 780 progname = argv[0]; 784 781 785 - while ((opt = getopt_long_only(argc, argv, "+a:c:d:hilms", long_options, 782 + while ((opt = getopt_long_only(argc, argv, "+a:c:d:hilmCs", long_options, 786 783 &option_index)) != -1) { 787 784 switch (opt) { 788 785 case 'd': ··· 798 793 break; 799 794 case 'm': 800 795 command = CMD_METER_CERT; 796 + break; 797 + case 'C': 798 + command = CMD_METER_CURRENT_CERT; 801 799 break; 802 800 case 's': 803 801 command = CMD_STATE_CERT; ··· 840 832 ret = sdsi_read_reg(s); 841 833 break; 842 834 case CMD_METER_CERT: 843 - ret = sdsi_meter_cert_show(s); 835 + ret = sdsi_meter_cert_show(s, false); 836 + break; 837 + case CMD_METER_CURRENT_CERT: 838 + ret = sdsi_meter_cert_show(s, true); 844 839 break; 845 840 case CMD_STATE_CERT: 846 841 ret = sdsi_state_cert_show(s);