kernel: move nsec to libc

This commit is contained in:
2017-01-06 00:45:35 +01:00
parent 2508de40ea
commit 4676c65a3d
7 changed files with 59 additions and 29 deletions

View File

@ -27,9 +27,9 @@ main(void)
uint64_t start, end; uint64_t start, end;
char *msg; char *msg;
start = sys_nsec(); start = sys_remove("#c/time");
sleep(1); sleep(1);
end = sys_nsec(); end = sys_remove("#c/time");
if (end <= start) if (end <= start)
ret = 1; ret = 1;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015 Giacomo Tesio <giacomo@tesio.it> * Copyright (C) 2015-2017 Giacomo Tesio <giacomo@tesio.it>
* *
* This file is part of the UCB release of Plan 9. It is subject to the license * This file is part of the UCB release of Plan 9. It is subject to the license
* terms in the LICENSE file found in the top-level directory of this * terms in the LICENSE file found in the top-level directory of this
@ -396,6 +396,7 @@ extern void longjmp(jmp_buf, int);
extern char* mktemp(char*); extern char* mktemp(char*);
extern double modf(double, double*); extern double modf(double, double*);
extern void notejmp(void*, jmp_buf, int); extern void notejmp(void*, jmp_buf, int);
extern unsigned long nsec(void);
extern int dup(int oldfd, int newfd); extern int dup(int oldfd, int newfd);
extern int ocreate(const char* path, unsigned int omode, unsigned int perm); extern int ocreate(const char* path, unsigned int omode, unsigned int perm);
extern void perror(const char*); extern void perror(const char*);

View File

@ -1039,6 +1039,17 @@ consread(Chan *c, void *buf, long n, int64_t off)
return -1; /* never reached */ return -1; /* never reached */
} }
static void
consremove(Chan* c)
{
switch((uint32_t)c->qid.path){
default:
error(Eperm);
case Qtime:
errorl("fugit irreparabile tempus", todget(nil));
}
}
static long static long
conswrite(Chan *c, void *va, long n, int64_t off) conswrite(Chan *c, void *va, long n, int64_t off)
{ {
@ -1198,7 +1209,7 @@ Dev consdevtab = {
devbread, devbread,
conswrite, conswrite,
devbwrite, devbwrite,
devremove, consremove,
devwstat, devwstat,
}; };

View File

@ -1163,9 +1163,3 @@ syssemrelease(int* addr, int delta)
return semrelease(s, addr, delta); return semrelease(s, addr, delta);
} }
long
sysnsec(void)
{
return todget(nil);
}

30
sys/src/lib/c/9sys/nsec.c Normal file
View File

@ -0,0 +1,30 @@
/*
* This file is part of Jehanne.
*
* Copyright (C) 2017 Giacomo Tesio <giacomo@tesio.it>
*
* Jehanne is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2 of the License.
*
* Jehanne is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Jehanne. If not, see <http://www.gnu.org/licenses/>.
*/
#define PORTABLE_SYSCALLS
#include <u.h>
#include <libc.h>
unsigned long
nsec(void)
{
long r;
r = remove("/dev/time");
if(r == -1)
r = remove("#c/time");
return r;
}

View File

@ -59,6 +59,7 @@
"9sys/getppid.c", "9sys/getppid.c",
"9sys/getwd.c", "9sys/getwd.c",
"9sys/iounit.c", "9sys/iounit.c",
"9sys/nsec.c",
"9sys/nulldir.c", "9sys/nulldir.c",
"9sys/ocreate.c", "9sys/ocreate.c",
"9sys/pipe.c", "9sys/pipe.c",

View File

@ -202,19 +202,12 @@
"int" "int"
] ]
}, },
{
"Id": 16,
"Name": "nsec",
"Ret": [
"long"
]
},
{ {
"Args": [ "Args": [
"const char*", "const char*",
"uint32_t" "uint32_t"
], ],
"Id": 17, "Id": 16,
"Name": "open", "Name": "open",
"Ret": [ "Ret": [
"long" "long"
@ -227,7 +220,7 @@
"long", "long",
"long" "long"
], ],
"Id": 18, "Id": 17,
"Name": "pread", "Name": "pread",
"Ret": [ "Ret": [
"long" "long"
@ -240,7 +233,7 @@
"long", "long",
"long" "long"
], ],
"Id": 19, "Id": 18,
"Name": "pwrite", "Name": "pwrite",
"Ret": [ "Ret": [
"long" "long"
@ -250,7 +243,7 @@
"Args": [ "Args": [
"const char*" "const char*"
], ],
"Id": 20, "Id": 19,
"Name": "remove", "Name": "remove",
"Ret": [ "Ret": [
"long" "long"
@ -261,7 +254,7 @@
"const void*", "const void*",
"void*" "void*"
], ],
"Id": 21, "Id": 20,
"Name": "rendezvous", "Name": "rendezvous",
"Ret": [ "Ret": [
"void*" "void*"
@ -271,7 +264,7 @@
"Args": [ "Args": [
"uint32_t" "uint32_t"
], ],
"Id": 22, "Id": 21,
"Name": "rfork", "Name": "rfork",
"Ret": [ "Ret": [
"int" "int"
@ -283,7 +276,7 @@
"long", "long",
"int" "int"
], ],
"Id": 23, "Id": 22,
"Name": "seek", "Name": "seek",
"Ret": [ "Ret": [
"long" "long"
@ -294,7 +287,7 @@
"int*", "int*",
"int" "int"
], ],
"Id": 24, "Id": 23,
"Name": "semacquire", "Name": "semacquire",
"Ret": [ "Ret": [
"int" "int"
@ -305,7 +298,7 @@
"int*", "int*",
"int" "int"
], ],
"Id": 25, "Id": 24,
"Name": "semrelease", "Name": "semrelease",
"Ret": [ "Ret": [
"int" "int"
@ -316,7 +309,7 @@
"int*", "int*",
"uint64_t" "uint64_t"
], ],
"Id": 26, "Id": 25,
"Name": "tsemacquire", "Name": "tsemacquire",
"Ret": [ "Ret": [
"int" "int"
@ -327,7 +320,7 @@
"const char*", "const char*",
"const char*" "const char*"
], ],
"Id": 27, "Id": 26,
"Name": "unmount", "Name": "unmount",
"Ret": [ "Ret": [
"int" "int"
@ -337,7 +330,7 @@
"Args": [ "Args": [
"unsigned long" "unsigned long"
], ],
"Id": 28, "Id": 27,
"Name": "alarm", "Name": "alarm",
"Ret": [ "Ret": [
"long" "long"