예제 #1
0
static int intel_hsw_imc_begin(struct stats_type *type)
{
  int nr = 0;

  uint32_t imc_events[4][4] = {
    { CAS_READS, CAS_WRITES, ACT_COUNT, PRE_COUNT_MISS,},
    { CAS_READS, CAS_WRITES, ACT_COUNT, PRE_COUNT_MISS,},
    { CAS_READS, CAS_WRITES, ACT_COUNT, PRE_COUNT_MISS,},
    { CAS_READS, CAS_WRITES, ACT_COUNT, PRE_COUNT_MISS,},
  };

  /* 2-4 buses and 4 devices per bus */
  char **bus;
  int num_buses;
  num_buses = get_pci_busids(&bus);

  char *dev[4] = {"14.0", "14.1", "17.0", "17.1"};
  int  ids[4] = {0x2fb0, 0x2fb1, 0x2fd0, 0x2fd1}; 
  char bus_dev[80];

  int i, j;
  for (i = 0; i < num_buses; i++) {
    for (j = 0; j < 4; j++) {
      // bus and device name
      snprintf(bus_dev, sizeof(bus_dev), "%s/%s", bus[i], dev[j]);
      if (check_pci_id(bus_dev, ids[j]))
	if (intel_hsw_imc_begin_dev(bus_dev, imc_events[j], 4) == 0)
	  nr++; /* HARD */    
    }
  }

  return nr > 0 ? 0 : -1;
}
예제 #2
0
static void intel_hsw_imc_collect(struct stats_type *type)
{
  /* 2-4 buses and 4 devices per bus */
  char **bus;
  int num_buses;
  num_buses = get_pci_busids(&bus);

  //char *dev[4] = {"14.0", "14.1", "15.0", "15.1", "17.0", "17.1", "18.0", "18.1"};
  //int   ids[4] = {0x2fb4, 0x2fb5, 0x2fb0, 0x2fb1, 0x2fd4, 0x2fd5, 0x2fd0, 0x2fd1}; 
  char *dev[4] = {"14.0", "14.1", "17.0", "17.1"};
  int   ids[4] = {0x2fb0, 0x2fb1, 0x2fd0, 0x2fd1}; 
  char bus_dev[80];                                        
  char socket_dev[80];

  int i, j;
  for (i = 0; i < num_buses; i++) {
    for (j = 0; j < 4; j++) {
      snprintf(bus_dev, sizeof(bus_dev), "%s/%s", bus[i], dev[j]);
      snprintf(socket_dev, sizeof(socket_dev), "%d/%s", i, dev[j]);
      if (check_pci_id(bus_dev,ids[j]))
	intel_hsw_imc_collect_dev(type, bus_dev, socket_dev);
    }
  }
}
/**
 * mv_indicator_list - Build Marvell HDD LED (indicator) list for the given disk vpd
 *
 * @list	loc_code structure
 * @vpd		dev_vpd structure
 *
 * Return:
 * -  0 on success or skip vpd (not a Marvell SATA disk)
 * - -1 on failure
 */
static int
mv_indicator_list(struct loc_code **list, struct dev_vpd *vpd)
{
	struct	loc_code *list_curr, *list_new;
	char	path[PATH_MAX], symlink[PATH_MAX];
	char	*ata_device, *host;
	ssize_t	len;

	/* check for an 'sdX' device name */
	if (strncmp(vpd->dev, "sd", 2))
		return 0;

	/* read the '/sys/block/sdX' symlink to '../device/pci.../sdX' */
	snprintf(path, PATH_MAX, "%s/%s", SYS_BLOCK_PATH, vpd->dev);

	len = readlink(path, symlink, PATH_MAX);
	if (len < 0) {
		log_msg("Unable to read the contents of symbolic link '%s'", path);
		return -1;
	}
	symlink[len] = '\0';

	/*
	 * check for an 'ataX' subdir (w/ trailing 'X' digit); for example 'ata1' in
	 * '../devices/pci<...>/0001:08:00.0/ata1/host3/target3:0:0/3:0:0:0/block/sdj'
	 */

	ata_device = strstr(symlink, "/ata");
	if (!ata_device || !isdigit(ata_device[4]))
		return 0;

	host = strstr(symlink, "/host");
	if (!host || !isdigit(host[5]))
		return 0;

	/* split symlink into relative path for PCI device dir and ataX device */
	ata_device[0] = '\0';	/* end symlink on leading '/' of '/ataX/' */
	ata_device++;		/* skip the leading '/' of '/ataX/' */
	host[0] = '\0';		/* end ata_device on trailing '/' of '/ataX/',
				 * which is the leading '/' of '/hostY/' */

	/*
	 * get the absolute path for the PCI device dir from symlink,
	 * which is relative to /sys/block (e.g., '../devices/pci...'),
	 * so skip the leading '../' (3 chars)
	 */
	len = snprintf(path, PATH_MAX, "%s/%s", "/sys", &symlink[3]);
	if (len < 0) {
		log_msg("Unable to format absolute pathname of '%s'", symlink);
		return -1;
	}

	/*
	 * check for the PCI IDs of the Marvell 9235 SATA controller.
	 *
	 * concatenate the PCI ID files' basename after the dirname
	 * with strncpy() (string length + 1 for '\0').
	 */
	strncpy(&path[len], "/vendor", 8);
	if (check_pci_id(path, MV_PCI_VID))
		return 0;

	strncpy(&path[len], "/device", 8);
	if (check_pci_id(path, MV_PCI_DID))
		return 0;

	strncpy(&path[len], "/subsystem_vendor", 18);
	if (check_pci_id(path, MV_PCI_SVID))
		return 0;

	strncpy(&path[len], "/subsystem_device", 18);
	if (check_pci_id(path, MV_PCI_SSID))
		return 0;

	path[len] = '\0'; /* restore path as dirname of PCI device dir */

	/* Allocate one loc_code element, and insert/append it to the list */
	list_new = calloc(1, sizeof(struct loc_code));
	if (!list_new) {
		log_msg("Out of memory");
		return 1;
	}

	if (*list) {
		/* position list_curr in the last element of the list */
		list_curr = *list;
		while (list_curr->next)
			list_curr = list_curr->next;

		/* append the new element to the list */
		list_curr->next = list_new;
	} else {
		/* null list; insert the new element at the list head */
		*list = list_new;
	}

	/* set the new element's properties */
	list_new->type = TYPE_MARVELL;
	strncpy(list_new->code, vpd->location, LOCATION_LENGTH);  /* loc. code */
	strncpy(list_new->devname, vpd->dev, DEV_LENGTH);   /* sdX device name */
	snprintf(list_new->dev, DEV_LENGTH, "%s/resource5", path); /* PCI BAR5 */
	list_new->index = (uint32_t)atoi(&ata_device[3]); /* use for ATA index */

	dbg("Marvell HDD LED:");
	dbg("- location code: '%s'", list_new->code);
	dbg("- device name (disk): '%s'", list_new->devname);
	dbg("- device name (pci bar5): '%s'", list_new->dev);
	dbg("- ata index: '%u'", list_new->index);

	return 0;
}