Re: [PATCH gnumach] Update thread and task creation time to use time_value64_t

2023-03-12 Thread Samuel Thibault
Applied, thanks!

Flavio Cruz, le sam. 11 mars 2023 14:38:08 -0500, a ecrit:
> ---
>  kern/mach_clock.c | 13 +
>  kern/mach_clock.h |  4 ++--
>  kern/task.h   |  2 +-
>  kern/thread.h |  2 +-
>  4 files changed, 9 insertions(+), 12 deletions(-)
> 
> diff --git a/kern/mach_clock.c b/kern/mach_clock.c
> index a3656948..e33404a2 100644
> --- a/kern/mach_clock.c
> +++ b/kern/mach_clock.c
> @@ -417,12 +417,10 @@ clock_boottime_update(const struct time_value64 
> *new_time)
>   * frame.
>   */
>  void
> -record_time_stamp(time_value_t *stamp)
> +record_time_stamp(time_value64_t *stamp)
>  {
> - time_value64_t stamp64;
> - read_mapped_time(&stamp64);
> - time_value64_add(&stamp64, &clock_boottime_offset);
> - TIME_VALUE64_TO_TIME_VALUE(&stamp64, stamp);
> + read_mapped_time(stamp);
> + time_value64_add(stamp, &clock_boottime_offset);
>  }
>  
>  /*
> @@ -430,10 +428,9 @@ record_time_stamp(time_value_t *stamp)
>   * real-time clock frame.
>   */
>  void
> -read_time_stamp (const time_value_t *stamp, rpc_time_value_t *result)
> +read_time_stamp (const time_value64_t *stamp, rpc_time_value_t *result)
>  {
> - time_value64_t result64;
> - TIME_VALUE_TO_TIME_VALUE64(stamp, &result64);
> + time_value64_t result64 = *stamp;
>   time_value64_sub(&result64, &clock_boottime_offset);
>   TIME_VALUE64_TO_TIME_VALUE(&result64, result);
>  }
> diff --git a/kern/mach_clock.h b/kern/mach_clock.h
> index 9a670011..60b49b8a 100644
> --- a/kern/mach_clock.h
> +++ b/kern/mach_clock.h
> @@ -92,13 +92,13 @@ extern void init_timeout (void);
>   * Record a timestamp in STAMP.  Records values in the boot-time clock
>   * frame.
>   */
> -extern void record_time_stamp (time_value_t *stamp);
> +extern void record_time_stamp (time_value64_t *stamp);
>  
>  /*
>   * Read a timestamp in STAMP into RESULT.  Returns values in the
>   * real-time clock frame.
>   */
> -extern void read_time_stamp (const time_value_t *stamp, rpc_time_value_t 
> *result);
> +extern void read_time_stamp (const time_value64_t *stamp, rpc_time_value_t 
> *result);
>  
>  extern void mapable_time_init (void);
>  
> diff --git a/kern/task.h b/kern/task.h
> index 7e915e02..38aa9feb 100644
> --- a/kern/task.h
> +++ b/kern/task.h
> @@ -87,7 +87,7 @@ struct task {
>   time_value_ttotal_system_time;
>   /* total system time for dead threads */
>  
> - time_value_tcreation_time; /* time stamp at creation */
> + time_value64_t  creation_time; /* time stamp at creation */
>  
>   /* IPC structures */
>   decl_simple_lock_data(, itk_lock_data)
> diff --git a/kern/thread.h b/kern/thread.h
> index 689ef775..f8989f45 100644
> --- a/kern/thread.h
> +++ b/kern/thread.h
> @@ -204,7 +204,7 @@ struct thread {
>   unsigned intsched_delta;/* weighted cpu usage since update */
>  
>   /* Creation time stamp */
> - time_value_tcreation_time;
> + time_value64_t  creation_time;
>  
>   /* Time-outs */
>   timer_elt_data_t timer; /* timer for thread */
> -- 
> 2.39.2
> 
> 

-- 
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.



[PATCH gnumach] Use c_string to define host_get_kernel_version and host_get_kernel_boot_info.

2023-03-12 Thread Flavio Cruz
The existing definitions for kernel_version_t and kernel_boot_info_t use
(MACH_MSG_TYPE_STRING, length*8) which result in message types that have
a single element of 512 or 4096 bytes (set as msgt_size). This results
in MiG generating mach_msg_type_long_t. Using c_string has the benefit
of moving this size to be defined as msgt_number which doesn't overflow.
This will allow us to simplify the 64 bit RPC ABI since all msgt_size can
be defined with just 8 bits (as it should be expected).

The resulting implementation is the same but we still need to define new
RPCs since server and user expect different mach_msg_type_t.
---
 doc/mach.texi|  8 
 include/mach/mach_host.defs  | 16 
 include/mach/mach_types.defs |  4 
 kern/host.c  |  8 
 kern/machine.c   |  8 
 5 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/doc/mach.texi b/doc/mach.texi
index 3fdba3fc..2c22fa38 100644
--- a/doc/mach.texi
+++ b/doc/mach.texi
@@ -5577,8 +5577,8 @@ The minimum quantum and unit of quantum in milliseconds.
 This is a pointer to a @code{struct host_sched_info}.
 @end deftp
 
-@deftypefun kern_return_t host_kernel_version (@w{host_t @var{host}}, 
@w{kernel_version_t *@var{version}})
-The @code{host_kernel_version} function returns the version string
+@deftypefun kern_return_t host_get_kernel_version (@w{host_t @var{host}}, 
@w{kernel_version_t *@var{version}})
+The @code{host_get_kernel_version} function returns the version string
 compiled into the kernel executing on @var{host} at the time it was
 built in the character string @var{version}.  This string describes the
 version of the kernel.  The constant @code{KERNEL_VERSION_MAX} should be
@@ -5595,8 +5595,8 @@ inaccessible memory, it returns 
@code{KERN_INVALID_ADDRESS}, and
 @code{KERN_SUCCESS} otherwise.
 @end deftypefun
 
-@deftypefun kern_return_t host_get_boot_info (@w{host_priv_t @var{host_priv}}, 
@w{kernel_boot_info_t @var{boot_info}})
-The @code{host_get_boot_info} function returns the boot-time information
+@deftypefun kern_return_t host_get_kernel_boot_info (@w{host_priv_t 
@var{host_priv}}, @w{kernel_boot_info_t @var{boot_info}})
+The @code{host_get_kernel_boot_info} function returns the boot-time information
 string supplied by the operator to the kernel executing on
 @var{host_priv} in the character string @var{boot_info}.  The constant
 @code{KERNEL_BOOT_INFO_MAX} should be used to dimension storage for the
diff --git a/include/mach/mach_host.defs b/include/mach/mach_host.defs
index 223f4576..99b48b4b 100644
--- a/include/mach/mach_host.defs
+++ b/include/mach/mach_host.defs
@@ -163,6 +163,7 @@ routine task_get_assignment(
 
 /*
  * Get string describing current kernel version.
+ * Deprecated, use host_get_kernel_version.
  */
 routinehost_kernel_version(
host: host_t;
@@ -348,6 +349,7 @@ routine processor_control(
 
 /*
  *  Get boot configuration information from kernel.
+ *  Deprecated, use host_get_kernel_boot_info.
  */
 routine host_get_boot_info(
host_priv   : host_priv_t;
@@ -378,3 +380,17 @@ routinehost_adjust_time64(
host_priv   : host_priv_t;
in  new_adjustment  : time_value64_t;
out old_adjustment  : time_value64_t);
+
+/*
+ * Get string describing current kernel version.
+ */
+routinehost_get_kernel_version(
+   host: host_t;
+   out kernel_version  : new_kernel_version_t);
+
+/*
+ *  Get boot configuration information from kernel.
+ */
+routine host_get_kernel_boot_info(
+   host_priv   : host_priv_t;
+   out boot_info   : new_kernel_boot_info_t);
diff --git a/include/mach/mach_types.defs b/include/mach/mach_types.defs
index 8f22137a..e02e3e8a 100644
--- a/include/mach/mach_types.defs
+++ b/include/mach/mach_types.defs
@@ -256,8 +256,12 @@ type processor_set_name_array_t = ^array[] of 
processor_set_name_t;
 type processor_set_info_t  = array[*:1024] of integer_t;
 
 type kernel_version_t  = (MACH_MSG_TYPE_STRING, 512*8);
+type new_kernel_version_t = c_string[512]
+  ctype: kernel_version_t;
 
 type kernel_boot_info_t= (MACH_MSG_TYPE_STRING, 4096*8);
+type new_kernel_boot_info_t = c_string[4096]
+  ctype: kernel_boot_info_t;
 
 type rpc_time_value_t  = struct {
   rpc_long_integer_t seconds;
diff --git a/kern/host.c b/kern/host.c
index 7ce8edff..50f58e9c 100644
--- a/kern/host.c
+++ b/kern/host.c
@@ -219,6 +219,14 @@ kern_return_t host_kernel_version(
return KERN_SUCCESS;
 }
 
+/* Same as above */
+kern_return_t host_get_kernel_version(
+   const host_thost,
+   kernel_version_tout_version)
+{
+   return host_kernel_version(host, out_version);
+}
+
 /*
  * host_processor_sets:
  *
diff --git a/kern/machine.c b/kern/machine.c
index bf9677c9..c9e368a0 100644
--- a/kern/machine.c
+

[PATCH gnumach] Track task and thread time using time_value64_t.

2023-03-12 Thread Flavio Cruz
Changed kern/timer.c to use the higher precision time_value64_t.
Of course, this won't suffer from the 2038 overflow but it does provide
nanosecond precision (if gnumach ever uses a better timer) and
moves us closer to only having time_value64_t.
---
 include/mach/time_value.h |  5 +++
 kern/mach_clock.c |  7 ++--
 kern/mach_clock.h |  2 +-
 kern/task.c   | 42 ++--
 kern/task.h   |  4 +-
 kern/thread.c | 19 +
 kern/timer.c  | 82 ---
 kern/timer.h  | 24 +++-
 8 files changed, 81 insertions(+), 104 deletions(-)

diff --git a/include/mach/time_value.h b/include/mach/time_value.h
index 0643b740..ea661ec3 100644
--- a/include/mach/time_value.h
+++ b/include/mach/time_value.h
@@ -140,6 +140,11 @@ static __inline__ time_value_t 
convert_time_value_from_user(rpc_time_value_t tv)
 time_value64_sub_nanos(result, (subtrahend)->nanoseconds); \
   }
 
+#define time_value64_init(tv)  {   
\
+   (tv)->seconds = 0;  

\
+   (tv)->nanoseconds = 0;  
\
+   }
+
 #define TIME_VALUE64_TO_TIME_VALUE(tv64, tv) do {  \
(tv)->seconds = (tv64)->seconds;
\
(tv)->microseconds = (tv64)->nanoseconds / 1000;\
diff --git a/kern/mach_clock.c b/kern/mach_clock.c
index e33404a2..65c38086 100644
--- a/kern/mach_clock.c
+++ b/kern/mach_clock.c
@@ -428,11 +428,10 @@ record_time_stamp(time_value64_t *stamp)
  * real-time clock frame.
  */
 void
-read_time_stamp (const time_value64_t *stamp, rpc_time_value_t *result)
+read_time_stamp (const time_value64_t *stamp, time_value64_t *result)
 {
-   time_value64_t result64 = *stamp;
-   time_value64_sub(&result64, &clock_boottime_offset);
-   TIME_VALUE64_TO_TIME_VALUE(&result64, result);
+   *result = *stamp;
+   time_value64_sub(result, &clock_boottime_offset);
 }
 
 
diff --git a/kern/mach_clock.h b/kern/mach_clock.h
index 60b49b8a..66903b8a 100644
--- a/kern/mach_clock.h
+++ b/kern/mach_clock.h
@@ -98,7 +98,7 @@ extern void record_time_stamp (time_value64_t *stamp);
  * Read a timestamp in STAMP into RESULT.  Returns values in the
  * real-time clock frame.
  */
-extern void read_time_stamp (const time_value64_t *stamp, rpc_time_value_t 
*result);
+extern void read_time_stamp (const time_value64_t *stamp, time_value64_t 
*result);
 
 extern void mapable_time_init (void);
 
diff --git a/kern/task.c b/kern/task.c
index be385a1b..65191f5d 100644
--- a/kern/task.c
+++ b/kern/task.c
@@ -154,10 +154,8 @@ task_create_kernel(
ipc_task_init(new_task, parent_task);
machine_task_init (new_task);
 
-   new_task->total_user_time.seconds = 0;
-   new_task->total_user_time.microseconds = 0;
-   new_task->total_system_time.seconds = 0;
-   new_task->total_system_time.microseconds = 0;
+   time_value64_init(&new_task->total_user_time);
+   time_value64_init(&new_task->total_system_time);
 
record_time_stamp (&new_task->creation_time);
 
@@ -808,16 +806,13 @@ kern_return_t task_info(
task_lock(task);
basic_info->base_priority = task->priority;
basic_info->suspend_count = task->user_stop_count;
-   basic_info->user_time.seconds
-   = task->total_user_time.seconds;
-   basic_info->user_time.microseconds
-   = task->total_user_time.microseconds;
-   basic_info->system_time.seconds
-   = task->total_system_time.seconds;
-   basic_info->system_time.microseconds
-   = task->total_system_time.microseconds;
-   read_time_stamp(&task->creation_time,
-   &basic_info->creation_time);
+   TIME_VALUE64_TO_TIME_VALUE(&task->total_user_time,
+   &basic_info->user_time);
+   TIME_VALUE64_TO_TIME_VALUE(&task->total_system_time,
+   &basic_info->system_time);
+   time_value64_t creation_time64;
+   read_time_stamp(&task->creation_time, &creation_time64);
+   TIME_VALUE64_TO_TIME_VALUE(&creation_time64, 
&basic_info->creation_time);
task_unlock(task);
 
if (*task_info_count > TASK_BASIC_INFO_COUNT)
@@ -854,21 +849,22 @@ kern_return_t task_info(
task_thread_times_info_t times_info;
thread_tthread;
 
-   if (*task

[PATCH gnumach] Use host_get_time64 in glue code

2023-03-12 Thread Flavio Cruz
---
 linux/dev/glue/misc.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/linux/dev/glue/misc.c b/linux/dev/glue/misc.c
index 92541c7b..5646e5ea 100644
--- a/linux/dev/glue/misc.c
+++ b/linux/dev/glue/misc.c
@@ -235,7 +235,10 @@ do_gettimeofday (struct timeval *tv)
* expensive, and the host argument is not used by host_get_time (),
* only checked not to be HOST_NULL.
*/
-  host_get_time ((host_t) 1, (time_value_t *) tv);
+  time_value64_t tv64;
+  host_get_time64 ((host_t) 1, &tv64);
+  tv->tv_sec = tv64.seconds;
+  tv->tv_usec = tv64.nanoseconds / 1000;
 }
 
 int
-- 
2.39.2