Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

posix clock: unexpected value for CLOCK_REALTIME when used with newlib #20167

Closed
sdalu opened this issue Oct 26, 2019 · 6 comments
Closed

posix clock: unexpected value for CLOCK_REALTIME when used with newlib #20167

sdalu opened this issue Oct 26, 2019 · 6 comments
Assignees
Labels
area: POSIX POSIX API Library bug The issue is a bug, or the PR is fixing a bug

Comments

@sdalu
Copy link
Contributor

sdalu commented Oct 26, 2019

When compiling with newlib and posix clock enabled, and so using sys/time.h,
call to clock_settime will failed due to CLOCK_REALTIME having differente values
(0 in posix/clock.c file, 1 in main.c)

CONFIG_NEWLIB_LIBC=y
CONFIG_POSIX_CLOCK=y
#include <zephyr.h>
#include <sys/time.h>
/* using posix/time.h (as in posix/clock.c), instead of sys/time.h will print 
 * a different value for CLOCK_REALTIME 
 */

void main(void) {
    printk("CLOCK_REALTIME: %ld\n", CLOCK_REALTIME);
}
@sdalu sdalu added the bug The issue is a bug, or the PR is fixing a bug label Oct 26, 2019
@aescolar aescolar added the area: POSIX POSIX API Library label Oct 27, 2019
@pabigot
Copy link
Collaborator

pabigot commented Oct 27, 2019

I'm unable to reproduce this using what you provided as prj.conf and src/main.c in samples/hello_world on nrf52840_pca10056. The build succeeds and I get:

Hello World! nrf52840_pca10056 1
***** Booting Zephyr OS build zephyr-v2.0.0-1547-gda5a595f248f *****
CLOCK_REALTIME: 1

Are you using some other platform? native_posix for example, where it does fail as you describe?

I think that would be an unsupported configuration (Zephyr's POSIX implementation surely can't co-exist with a host POSIX implementation) but defer to @pfalcon.

@pabigot pabigot added the priority: low Low impact/importance bug label Oct 27, 2019
@sdalu
Copy link
Contributor Author

sdalu commented Oct 27, 2019

i'm using nrf52840_mdk. Did you get 1 also using (posix/time.h):

#include <zephyr.h>
#include <posix/time.h>

void main(void) {
    printk("CLOCK_REALTIME: %ld\n", CLOCK_REALTIME);
}

@pabigot pabigot assigned pfalcon and unassigned pabigot Oct 27, 2019
@pabigot
Copy link
Collaborator

pabigot commented Oct 27, 2019

Sorry, I didn't read what you wrote here closely enough.

Yes, I see the values are different. I suspect the best approach here would be to work #18892 so Zephyr only provides values that are not defined by a standard header provided by the toolchain. That would need to be scheduled based on POSIX subsystem needs.

@pabigot pabigot removed the priority: low Low impact/importance bug label Oct 27, 2019
@pabigot
Copy link
Collaborator

pabigot commented Oct 28, 2019

This appears to be fixed by e5b462b which was hidden inside #19114 and was merged earlier today. Please re-open if it still doesn't work.

@pabigot pabigot closed this as completed Oct 28, 2019
@pfalcon
Copy link
Contributor

pfalcon commented Oct 28, 2019

This appears to be fixed by e5b462b which was hidden inside #19114 and was merged earlier today.

More specifically, I ack and confirm this issue. It's one of many conflicts related to Zephyr's POSIX subsystem, which get tracked and persistently fixed since the beginning of this year following the approach "POSIX subsys and libc should cooperate, not compete, and newlib should be used as a pattern/convention for libc interfacing (i.e. e.g. minlibc should behave/be structured as newlibc)".

I've seen this particular issue before, but it was forgotten/lost while looking into other issue. It sufaced again while performing refactoring of #19114 based on its code review. Indeed, I would hope that the patch included there would fix the issue. I'm at a conference now though, so maybe be slow with confirming that the change also fixes this issue, so would appreciate independent verification. Thanks.

@sdalu
Copy link
Contributor Author

sdalu commented Oct 28, 2019

It's working for me, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: POSIX POSIX API Library bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

No branches or pull requests

4 participants