Skip to content

Commit

Permalink
Merge pull request #1964 from ghaerr/prectimer5
Browse files Browse the repository at this point in the history
[kernel/libc] Allow for concurrent operation of libc and kernel precision timer
  • Loading branch information
ghaerr authored Aug 14, 2024
2 parents 97b2434 + 4c86dda commit 7aba3e5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions elks/arch/i86/lib/prectimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ unsigned long get_ptime(void)
/* 16-bit subtract handles low word wrap automatically */
jdiff = (unsigned)jiffies - (unsigned)lastjiffies;
lastjiffies = (unsigned)jiffies; /* 16 bit save works for ~10.9 mins */
restore_flags(flags);

lo = inb(TIMER_DATA_PORT);
hi = inb(TIMER_DATA_PORT) << 8;
restore_flags(flags);

count = lo | hi;
pticks = lastcount - count;
if ((int)pticks < 0) /* wrapped */
Expand Down
1 change: 0 additions & 1 deletion libc/debug/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ OBJS = \
stacktrace.o \
printreg.o \
prectimer.o \
ptostr.o \
# end of list

#OBJS += rdtsc.o
Expand Down
10 changes: 6 additions & 4 deletions libc/debug/prectimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,21 @@ static unsigned int lastjiffies; /* only 16 bits required within ~10.9 mins *
#ifndef __KERNEL__
static unsigned short __far *pjiffies; /* only access low order jiffies word */

#define errmsg(str) write(STDERR_FILENO, str, sizeof(str) - 1)

void init_ptime(void)
{
int fd, offset, kds;

__LINK_SYMBOL(ptostr);
fd = open("/dev/kmem", O_RDONLY);
if (fd < 0) {
printf("No /dev/kmem\n");
errmsg("No kmem\n");
return;
}
if (ioctl(fd, MEM_GETDS, &kds) < 0 ||
ioctl(fd, MEM_GETJIFFADDR, &offset) < 0) {
printf("No ioctl mem_getds\n");
errmsg("No mem ioctl\n");
} else {
pjiffies = _MK_FP(kds, offset);
}
Expand Down Expand Up @@ -101,10 +103,10 @@ unsigned long get_ptime(void)
jdiff = (unsigned)jiffies - (unsigned)lastjiffies;
lastjiffies = (unsigned)jiffies; /* 16 bit save works for ~10.9 mins */
#endif
restore_flags(flags);

lo = inb(TIMER_DATA_PORT);
hi = inb(TIMER_DATA_PORT) << 8;
restore_flags(flags);

count = lo | hi;
pticks = lastcount - count;
if ((int)pticks < 0) /* wrapped */
Expand Down
1 change: 1 addition & 0 deletions libc/misc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ OBJS = \
lltostr.o \
mktemp.o \
popen.o \
ptostr.o \
putenv.o \
qsort.o \
rand.o \
Expand Down
8 changes: 4 additions & 4 deletions libc/debug/ptostr.c → libc/misc/ptostr.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
* Convert precision timing pticks (=0.838us) to string for printf %k format.
* This routine is normally weak linked into vfprintf by a get_ptime reference.
*/

static char dec_string[] = "0123456789 ";

void ptostr(unsigned long v, char *buf)
{
unsigned long dvr;
int c, vch, i;
int Msecs, Decimal, Zero;
int width = 0;
int Msecs, Decimal, Zero, width;
unsigned long dvr;

i = 10;
dvr = 1000000000L;
Zero = 0;
width = Zero = 0;
Msecs = 0;
/* display 1/1193182s get_time*() pticks in range 0.838usec through 42.85sec */
Decimal = 3;
Expand Down

0 comments on commit 7aba3e5

Please sign in to comment.