[ddccontrol-devel] Patch: accelerate ddccontrol -r From: Kiran Kotla - 2009-01-30 23:46 Hello ddccontrol maintainers, Here is a patch that makes ddccontrol run substantially faster when the i2c device and a field to read or write are specified, by skipping the reading of monitor information which is apparently not used in that case. This optimization makes it more feasible to use ddccontrol interactively for tasks like adjusting monitor brightness or picture position. Just as a sample benchmark, here is the difference in times to do "ddccontrol -r 0x60 pci:01:00.0-1", in seconds, which shows that ddccontrol runs more than twice as fast in this case. Real User Sys Before 2.191 0.136 0.052 After 0.788 0.148 0.044 The change basically chops the end of ddcci_open into a separate new function, ddcci_read_details, and changes the two places that call ddcci_open to call this second function also, but only when necessary. Although this patch is against ddccontrol-0.4.2, it should apply cleanly in the subversion trunk, as the only intervening changes to the effected file in subversion were changes to the mailing address of the Free Software Foundation. Since I do not have write access to the subversion repository, could you please integrate this change or let me know what process you would prefer I follow to get this optimization integrated? Thanks in advance. Kiran diff -u -r ddccontrol-0.4.2/src/ddccontrol/main.c ddccontrol-0.4.2.faster/src/ddccontrol/main.c --- ddccontrol-0.4.2/src/ddccontrol/main.c 2006-07-27 13:45:08.000000000 -0700 +++ ddccontrol-0.4.2.faster/src/ddccontrol/main.c 2009-01-30 12:45:03.000000000 -0800 @@ -343,6 +343,10 @@ "\nDDC/CI at %s is unusable (%d).\n" "If your graphics card need it, please check all the required kernel modules are loaded (i2c-dev, and your framebuffer driver).\n" ), fn, ret); + } else if (probe && (ret = ddcci_read_details(&mon)) < 0) { + fprintf(stderr, _( + "\nUnable to read monitor details from database (ddc_read_details returned %d).\n" + ), ret); } else { fprintf(stdout, _("\nEDID readings:\n")); fprintf(stdout, _("\tPlug and Play ID: %s [%s]\n"), diff -u -r ddccontrol-0.4.2/src/lib/ddcci.c ddccontrol-0.4.2.faster/src/lib/ddcci.c --- ddccontrol-0.4.2/src/lib/ddcci.c 2006-06-15 09:45:19.000000000 -0700 +++ ddccontrol-0.4.2.faster/src/lib/ddcci.c 2009-01-30 11:23:56.000000000 -0800 @@ -883,7 +883,7 @@ - -2 if EDID is not available - -3 if file can't be opened */ -static int ddcci_open_with_addr(struct monitor* mon, const char* filename, int addr, int edid, int probing) +static int ddcci_open_with_addr(struct monitor* mon, const char* filename, int addr, int probing) { memset(mon, 0, sizeof(struct monitor)); @@ -936,6 +936,11 @@ mon->addr = addr; + return 0; +} + +static int ddcci_read_details_edid(struct monitor* mon, int edid) +{ if (ddcci_read_edid(mon, edid) < 0) { return -2; } @@ -987,9 +992,15 @@ int ddcci_open(struct monitor* mon, const char* filename, int probing) { - return ddcci_open_with_addr(mon, filename, DEFAULT_DDCCI_ADDR, DEFAULT_EDID_ADDR, probing); + return ddcci_open_with_addr(mon, filename, DEFAULT_DDCCI_ADDR, probing); } +int ddcci_read_details(struct monitor* mon) +{