RFC: vid scaling does not belong in kernel?
Hi there,
vid and vrm are two of the strangest things I met in lmsensors.
Here we have user space telling kernel how to scale a value the kernel does nothing with. If I produce a set of patches to remove vid scaling from the drivers: adm1025.c, adm1026.c, asb100.c, it87.c, lm85.c, lm87.c, pc87360.c, w83627hf.c and w83781d.c we save nine write accessors and can remove the vrm stuff to user- space where it belongs, with the other scaling, simplifying the read accessors by removing the scaling requirement.
vid sense pins don't do anything, thus the vid sense state should be reported truthfully to user-space, it may do something with the value.
Please somebody tell me what I've missed here?
Cheers,
Grant.
Hi Grant,
Quoted 3 lines
So I don't have vrm, therfore I don't need to scale vid, that's the logical reduction I've been trying to reach. Why am I scaling a value when nothing can write access vrm?
You do have VRM, it is only auto-detected from the CPU model instead of being set by the user. You still need to convert {VID, VRM} into a voltage value.
And again your use of the term "scalling" here is confusing. What you do is convert a binary value into a voltage value.
Signature · 1 line
Jean Delvare
One thing that comes to mind is that the mapping of VID to voltage is not a simple linear function. For some of the standards it does funky things with some of the bits. So you won't be able to use the simple math operators like the other scaling functions in sensors.conf. You'd have to create a new, custom transform function that takes both the VID value and the VRM version. sensors.conf has a relatively simple equation parser. I'm not sure how easy it will be to add the VID to voltage function.
If we suck that into libsensors, then you *have* to use the library to convert the VID bit pattern into a voltage or re-implement the function in the userspace language of your choice (bash, perl, python, etc.) and since these VRM standards change seemingly with every CPU rev, all those user-space applications are going to be out of date at one point or another.
But the code that exists in the kernel sensor drivers today, checks the CPU, verifies which VRM standard applies to that rev of CPU and then produces the correct VID to voltage mapping automatically.
If you still want to proceed, I suggest you solve the sensors.conf side of the problem first. Make sure you can scale a raw VID bit pattern into a voltage for use in setting CPU core voltage limits. Then let's discuss changing the chip drivers.
:v)
Quoted 23 lines · Grant Coady
Hi there,
vid and vrm are two of the strangest things I met in lmsensors.
Here we have user space telling kernel how to scale a value the kernel does nothing with. If I produce a set of patches to remove vid scaling from the drivers:
adm1025.c,adm1026.c,asb100.c,it87.c,lm85.c,lm87.c,pc87360.c,w83627hf.candw83781d.cwe save nine write accessors and can remove the vrm stuff to user- space where it belongs, with the other scaling, simplifying the read accessors by removing the scaling requirement.vid sense pins don't do anything, thus the vid sense state should be reported truthfully to user-space, it may do something with the value.
Please somebody tell me what I've missed here?
Cheers,
Grant.
Hi Philip, Grant,
Quoted 3 lines
But the code that exists in the kernel sensor drivers today, checks the CPU, verifies which VRM standard applies to that rev of CPU and then produces the correct VID to voltage mapping automatically.
I would like to insist on this. The fact that vrm is writable is a legacy of the past. There is no more reason to set the vrm value now that Rudolf Marek added auto-detection stuff (which BTW should be ported back to lm_sensors CVS).
Even exporting the VRM version to user-space makes little sense now. This now only serves for debugging, but this would be more efficient to simply print the VRM value in the logs at the moment we detect it.
--
Jean Delvare
Quoted 7 lines · Jean Delvare
Hi Philip, Grant,
Quoted 3 lines
But the code that exists in the kernel sensor drivers today, checks the CPU, verifies which VRM standard applies to that rev of CPU and then produces the correct VID to voltage mapping automatically.
Quoted 8 lines
I would like to insist on this. The fact that vrm is writable is a legacy of the past. There is no more reason to set the vrm value now that Rudolf Marek added auto-detection stuff (which BTW should be ported back to
lm_sensorsCVS).Even exporting the VRM version to user-space makes little sense now. This now only serves for debugging, but this would be more efficient to simply print the VRM value in the logs at the moment we detect it.
That's one knocked over then, glad I asked before coding, just need to fix the odd-one-out: adm1026, to match the others then. Much less work.
So I don't have vrm, therfore I don't need to scale vid, that's the logical reduction I've been trying to reach. Why am I scaling a value when nothing can write access vrm?
Yeah, I'm missing something, too late, localtime... Cheers,
Grant.
Hi Jean, All,
Quoted 10 lines · Jean Delvare
Hi Grant,
Quoted 3 lines
So I don't have vrm, therfore I don't need to scale vid, that's the logical reduction I've been trying to reach. Why am I scaling a value when nothing can write access vrm?
You do have VRM, it is only auto-detected from the CPU model instead of being set by the user. You still need to convert {VID, VRM} into a voltage value.
s/scaling/mapping/ sorry, I knew what I meant :) So what I have missed is the connection to this auto-cpu-detect value for vrm. During last query on this some weeks? ago I was told make it settable from user-space, now it seems that is wrong track. I'll survey drivers using it and see if I can work it out. That's why I did the cross-reference stuff in first place, see which driver uses what to cherry-pick possible solutions.
Cheers,
Grant.
Quoted 2 lines · Philip Pokorny
One thing that comes to mind is that the mapping of VID to voltage is not a simple linear function.
The vid voltage mapping is presented in table format on data sheets, and I see absolutely no reason to use anything other than a table lookup, for that technique provides an audit trail back to data sheet.
The art of measurement is honesty, not an obfuscated code competition. "
The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague. -- Edsger W. Dijkstra
"
Cheers,
Grant.
Hi Grant, Philip,
Quoted 3 lines
The vid voltage mapping is presented in table format on data sheets, and I see absolutely no reason to use anything other than a table lookup, for that technique provides an audit trail back to data sheet.
And some (most?) datasheets present fan clock dividers as tables too. Are we going to convert div = (1 << n) into a 4- or 8-value table? Certainly not. So the fact that the datasheet represents it as a table isn't a valid reason alone for us to use a table in our implementation.
Also note that some drivers need to do the inverse operation, i.e. find out which VID code matches best a given voltage. This can't be done with a table-based implementation.
The fact is that the VID codes are not random. There are linear parts and bits with special meanings. Our code reflects that. Also, various VRM versions are partly compatible. Our code reflects that too.
If you want to audit that code, feel free to compare the output of our function with a static table of your own.
I believe that having conversion formulas is *less* error prone than having tables. Especially, VRM 10 is a 6-bit value, so a 64-value table would be required. It's quite easy to mess up one value and it can take decades before someone hits the problem.
Quoted 1 line
The art of measurement is honesty, not an obfuscated code competition.
You never saw obfuscated code, right? This one isn't. Our approach to the problem differs from yours. That doesn't make the code obfucated.
Quoted 4 lines
"The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague. -- Edsger W. Dijkstra"
That's an interesting theory (let alone the fact that it's off-topic, because there is no trick here). If we were following that theory to the letter, the kernel would most probably be very large and slow as hell. A certain amount of cleverness is required to write kernel code (or just about any code, for that matter). While Djikstra was a briliant mathematician, I just can't agree with him here. I would sure avoid stupid tricks, but clever tricks, by definition, are the key to efficient programming.
Those who attempt to write code and pretend they don't need to know any of the internals usually write poor code. You need to know the language well in order to write evolutive and maintainable code. And yo better know a little bit about the hardware itself if you want to write efficient low-level code.
--
Jean Delvare