All of lore.kernel.org
 help / color / mirror / Atom feed
* [Powertop] [RFC 6/9] replace pciutils usage with udevhwdb
@ 2015-06-01 16:09 Nanley Chery
  0 siblings, 0 replies; 3+ messages in thread
From: Nanley Chery @ 2015-06-01 16:09 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 2962 bytes --]

Signed-off-by: Nanley Chery <nanley.g.chery(a)intel.com>
---
 src/lib.cpp            | 27 +++++++++++++++++++++++++++
 src/lib.h              |  1 +
 src/tuning/runtime.cpp | 11 +++--------
 3 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/src/lib.cpp b/src/lib.cpp
index 5a9c6be..399d2bc 100644
--- a/src/lib.cpp
+++ b/src/lib.cpp
@@ -314,6 +314,33 @@ void cleanup_udev()
 	}
 }
 
+const char *upci_id_to_name(struct udev_device* dev, char* buffer)
+{
+	const char *uvendor = udev_device_get_sysattr_value(dev, "vendor");
+	const char *udevice = udev_device_get_sysattr_value(dev, "device");
+	uint16_t vendor = stoul(string(uvendor), NULL, 16);
+	uint16_t device = stoul(string(udevice), NULL, 16);
+	char modalias[64];
+	sprintf(modalias, "pci:v%08Xd%08X*", vendor, device);
+	const char *key1 = "ID_VENDOR_FROM_DATABASE";
+	const char *key2 = "ID_MODEL_FROM_DATABASE";
+
+	struct udev_hwdb *hwdb = udev_hwdb_new(udev_device_get_udev(dev));
+	struct udev_list_entry *entry;
+	udev_list_entry_foreach(entry, udev_hwdb_get_properties_list_entry(hwdb, modalias, 0))
+		if (strcmp(udev_list_entry_get_name(entry), key1) == 0)
+			uvendor =  udev_list_entry_get_value(entry);
+		else if (strcmp(udev_list_entry_get_name(entry), key2) == 0)
+			udevice =  udev_list_entry_get_value(entry);
+
+	if (uvendor && udevice) {
+		sprintf(buffer, "%s %s", uvendor, udevice);
+		return buffer;
+	}
+
+	return NULL;
+}
+
 #ifndef HAVE_NO_PCI
 static struct pci_access *pci_access;
 
diff --git a/src/lib.h b/src/lib.h
index ae0421f..464ce71 100644
--- a/src/lib.h
+++ b/src/lib.h
@@ -68,6 +68,7 @@ extern string read_sysfs_string(const char *format, const char *param);
 
 extern void format_watts(double W, char *buffer, unsigned int len);
 
+extern const char *upci_id_to_name(struct udev_device* dev, char* buffer);
 extern char *pci_id_to_name(uint16_t vendor, uint16_t device, char *buffer, int len);
 extern void end_pci_access(void);
 
diff --git a/src/tuning/runtime.cpp b/src/tuning/runtime.cpp
index 463372d..ac65522 100644
--- a/src/tuning/runtime.cpp
+++ b/src/tuning/runtime.cpp
@@ -42,16 +42,11 @@ runtime_tunable::runtime_tunable(struct udev_device* udev_device) :
 	const char *dev = udev_device_get_sysname(udev_device);
 
 	/* Give more accurate descriptions for PCI devices */
+	char devname[4096];
 	if (strcmp(bus, "pci") == 0) {
-		const char *uvendor = udev_device_get_sysattr_value(udev_device, "vendor");
-		const char *udevice = udev_device_get_sysattr_value(udev_device, "device");
-		uint16_t vendor = stoul(string(uvendor), NULL, 16);
-		uint16_t device = stoul(string(udevice), NULL, 16);
+		if (upci_id_to_name(udev_device, devname))
+			dev = devname;
 		bus = "PCI";
-		if (vendor && device) {
-			char filename[4096];
-			dev = pci_id_to_name(vendor, device, filename, 4095);
-		}
 	}
 
 	if (!udevice_has_runtime_pm(udev_device))
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Powertop] [RFC 6/9] replace pciutils usage with udevhwdb
@ 2015-06-01 16:15 Arjan van de Ven
  0 siblings, 0 replies; 3+ messages in thread
From: Arjan van de Ven @ 2015-06-01 16:15 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 228 bytes --]

On 6/1/2015 9:09 AM, Nanley Chery wrote:
> Signed-off-by: Nanley Chery <nanley.g.chery(a)intel.com>

no commit message?



also on some OSes the udevhwdb for PCI names is empty and the pciutils explicit file is needed


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Powertop] [RFC 6/9] replace pciutils usage with udevhwdb
@ 2015-06-03 20:33 Nanley Chery
  0 siblings, 0 replies; 3+ messages in thread
From: Nanley Chery @ 2015-06-03 20:33 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 621 bytes --]

On Mon, Jun 1, 2015 at 9:15 AM, Arjan van de Ven <arjan(a)linux.intel.com> wrote:
> On 6/1/2015 9:09 AM, Nanley Chery wrote:
>>
>> Signed-off-by: Nanley Chery <nanley.g.chery(a)intel.com>
>
>
> no commit message?
I've been sitting on these patches for a while and just wanted to get
them out into the open. Most of my comments are in the cover letter.
I'll try to be better about commit messages in the future however.

>
> also on some OSes the udevhwdb for PCI names is empty and the pciutils
> explicit file is needed
I can't think of any work-around to this issue. pciutils will have to
stick around.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-06-03 20:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-01 16:15 [Powertop] [RFC 6/9] replace pciutils usage with udevhwdb Arjan van de Ven
  -- strict thread matches above, loose matches on Subject: below --
2015-06-03 20:33 Nanley Chery
2015-06-01 16:09 Nanley Chery

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.