drivers/cpu: add function to get CPU id/serial number#854
drivers/cpu: add function to get CPU id/serial number#854miri64 merged 2 commits intoRIOT-OS:masterfrom
Conversation
|
Where is the connection to #19 ? |
|
Ah I guess you used the wrong repo but the right number... |
|
Still it's circular reasoning - what should this be used for? |
|
I think it might be used to generate a host UID or EUI for the network interface. |
|
First: we discussed some time ago to use the cpu id as a (bad) source of randomness. Second: see #837 |
|
(maybe @haukepetersen and @thomaseichinger could look over it, too, and give suggestions for other CPU implementations) |
|
ACK |
cpu/native/include/cpu.h
Outdated
There was a problem hiding this comment.
I'd go with the process ID (compare #700) for starters.
|
Applied @LudwigOrtmann's and @kaspar030's comments. |
|
ACK for the core change. |
cpu/native/native_cpu.c
Outdated
There was a problem hiding this comment.
why a double memset?
why &id[0] same as id ?
|
Added a commit with an alternative suggestion based on OlegHahm/thirdparty_cpu#21 (comment) please review. |
core/include/kernel.h
Outdated
There was a problem hiding this comment.
What is cpu_id_len needed for? Can't the cpu set CPU_ID_MAX_LEN?
There was a problem hiding this comment.
I mean - without cpu_id_len one could simply use sizeof(cpu_id_t)..
There was a problem hiding this comment.
Then how do you propose to set CPU_ID_MAX_LEN to sizeof(pid_t) on native without including unistd.h and risking this way to come into conflict with our own posix port?
There was a problem hiding this comment.
ah hm uhm eh... one could get nasty here and define it via make
There was a problem hiding this comment.
I mean - have a test-program that determines this...
There was a problem hiding this comment.
long can only be trusted to be >= int.
There was a problem hiding this comment.
But at least for the *nix systems we support it seems to be the source for the typedef of pid_t
There was a problem hiding this comment.
Alternatively we can just say cpu_id_len may allways be 4 in native, and if the pid does not supply enough bytes for the rest is set to 0xff or 0x00 or whatever.
There was a problem hiding this comment.
The reason to trust pid_t to fit in long would be that:
blksize_t, pid_t, and ssize_t shall be signed integer types
The implementation shall support one or more programming environments in which the widths of blksize_t, pid_t, size_t, ssize_t, suseconds_t, and useconds_t are no greater than the width of type long.
There was a problem hiding this comment.
And yes, I'd memset it before like @authmillenon said.
|
Applied discussed changes and rebased. Also: updated #837 accordingly. |
|
ACK |
|
Needs second ACK because of core change (Re-ACK from @kaspar030?) |
cpu/native/include/cpu.h
Outdated
There was a problem hiding this comment.
Put parentheses around the macro argument.
|
Rebased, squashed and applied suggestions. |
|
needs rebase |
|
done |
|
(still/again) needs rebase |
|
@authmillenon ping |
|
Please rebase. |
|
Done |
|
Uses functionality of #1192 |
|
And addressed comments in #837 |
tests/test_cpu_id/main.c
Outdated
|
re-ACK |
|
Maybe you can refresh my memory - why is If it really should be implemented as a macro I'd opt for the documentation to indicate that it can't be trusted. |
|
Just was thinking the same thing as @LudwigOrtmann: what reason did we have to implement it as a macro, and why should it be part of the kernel? Now that I look at it: wouldn't it make more sense to specify a driver interface that reads out the cpu_id? |
|
I think my reasoning behind using a macro was that it mostly is just the reading of some registers, but true: this can also be done in a function. For the driver: You might be right. I'll look into it. |
|
You a-lookin' yet? |
|
Since there are more pressing issues right now, I postponed that. ;-) But the general idea is: yes it will be some sort of cpu or random-source "driver". |
|
I just thought the only thing left to do was creating this function.. |
|
... and this is a fix me first ... |
|
I discussed this with @haukepetersen and we both agreed that it would make much more sence to put this function into a driver header instead of kernel.h. Apart from that, the more pressing issues I'm working are also fix me firsts and are much more needed functionality (working ND, working Border Router) ;-) |
|
You can close this PR, if it irritates you... |
|
getter is now a function in its own driver module |
|
You made Travis cry. |
There was a problem hiding this comment.
I would suggest a comment on this define.
|
Æck! |
|
ACK |
drivers/cpu: add function to get CPU id/serial number
See OlegHahm/thirdparty_cpu#19 for real world example.