Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address CR feedback
  • Loading branch information
am11 committed Oct 31, 2021
commit 4a542e0389e2ace96e9b6229c38ac849709e2edb
2 changes: 1 addition & 1 deletion src/libraries/Native/Unix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ if (CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS
add_definitions(-D__APPLE_USE_RFC_3542)
endif ()

if (CLR_CMAKE_TARGET_LINUX)
if (CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_ANDROID)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE")
endif ()

Expand Down
2 changes: 1 addition & 1 deletion src/mono/cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@
#cmakedefine GLIBC_BEFORE_2_3_4_SCHED_SETAFFINITY 1

/* GLIBC has CPU_COUNT macro in sched.h */
#cmakedefine GLIBC_HAS_CPU_COUNT 1
#cmakedefine HAVE_GNU_CPU_COUNT

/* Have large file support */
#cmakedefine HAVE_LARGE_FILE_SUPPORT 1
Expand Down
48 changes: 29 additions & 19 deletions src/mono/cmake/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,36 @@ check_type_size("long" SIZEOF_LONG)
check_type_size("long long" SIZEOF_LONG_LONG)
check_type_size("size_t" SIZEOF_SIZE_T)

set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
if (HOST_LINUX OR HOST_ANDROID)
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
endif()

check_c_source_compiles(
"
#include <string.h>
int main(void)
{
char buffer[1];
char c = *strerror_r(0, buffer, 0);
return 0;
}
"
HAVE_GNU_STRERROR_R)

check_c_source_compiles(
"
#include <string.h>
int main(void)
{
char buffer[1];
char c = *strerror_r(0, buffer, 0);
return 0;
}
"
HAVE_GNU_STRERROR_R)
"
#include <sched.h>
int main(void)
{
CPU_COUNT((void *) 0);
return 0;
}
"
HAVE_GNU_CPU_COUNT)

if (HOST_LINUX OR HOST_ANDROID)
set(CMAKE_REQUIRED_DEFINITIONS)
endif()

# ICONV
set(ICONV_LIB)
Expand All @@ -145,14 +163,6 @@ if(NOT LIBICONV_FOUND STREQUAL "LIBICONV_FOUND-NOTFOUND")
set(ICONV_LIB "iconv")
endif()

file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test.c
"#include <sched.h>\n"
"void main () { CPU_COUNT((void *) 0); }\n"
)
try_compile(GLIBC_HAS_CPU_COUNT ${CMAKE_BINARY_DIR}/CMakeTmp SOURCES "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test.c"
COMPILE_DEFINITIONS "-D_GNU_SOURCE")


if(HOST_WIN32)
# checking for this doesn't work for some reason, hardcode result
set(HAVE_WINTERNL_H 1)
Expand Down
28 changes: 14 additions & 14 deletions src/mono/mono/utils/mono-proclib.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
# define kinfo_name_member p_comm
#elif defined(__OpenBSD__)
// Can not figure out how to get the proc's start time on OpenBSD
# undef kinfo_starttime_member
# undef kinfo_starttime_member
# define kinfo_pid_member p_pid
# define kinfo_name_member p_comm
#else
Expand All @@ -81,7 +81,7 @@
#endif

#ifdef HAVE_SCHED_GETAFFINITY
# ifndef GLIBC_HAS_CPU_COUNT
# ifndef HAVE_GNU_CPU_COUNT
static int
CPU_COUNT(cpu_set_t *set)
{
Expand Down Expand Up @@ -430,7 +430,7 @@ mono_process_get_times (gpointer pid, gint64 *start_time, gint64 *user_time, gin

/*
* /proc/pid/stat format:
* pid (cmdname) S
* pid (cmdname) S
* [0] ppid pgid sid tty_nr tty_pgrp flags min_flt cmin_flt maj_flt cmaj_flt
* [10] utime stime cutime cstime prio nice threads 0 start_time vsize
* [20] rss rsslim start_code end_code start_stack esp eip pending blocked sigign
Expand All @@ -445,7 +445,7 @@ mono_process_get_times (gpointer pid, gint64 *start_time, gint64 *user_time, gin
static gint64
get_process_stat_item (int pid, int pos, int sum, MonoProcessError *error)
{
#if defined(__APPLE__)
#if defined(__APPLE__)
double process_user_time = 0, process_system_time = 0;//, process_percent = 0;
task_t task;
struct task_basic_info t_info;
Expand Down Expand Up @@ -479,16 +479,16 @@ get_process_stat_item (int pid, int pos, int sum, MonoProcessError *error)
do {
ret = task_threads (task, &th_array, &th_count);
} while (ret == KERN_ABORTED);

if (ret != KERN_SUCCESS) {
if (pid != getpid ())
mach_port_deallocate (mach_task_self (), task);
RET_ERROR (MONO_PROCESS_ERROR_OTHER);
}

for (i = 0; i < th_count; i++) {
double thread_user_time, thread_system_time;//, thread_percent;

struct thread_basic_info th_info;
mach_msg_type_number_t th_info_count = THREAD_BASIC_INFO_COUNT;
do {
Expand All @@ -499,13 +499,13 @@ get_process_stat_item (int pid, int pos, int sum, MonoProcessError *error)
thread_user_time = th_info.user_time.seconds + th_info.user_time.microseconds / 1e6;
thread_system_time = th_info.system_time.seconds + th_info.system_time.microseconds / 1e6;
//thread_percent = (double)th_info.cpu_usage / TH_USAGE_SCALE;

process_user_time += thread_user_time;
process_system_time += thread_system_time;
//process_percent += th_percent;
}
}

for (i = 0; i < th_count; i++)
mach_port_deallocate(task, th_array[i]);

Expand All @@ -514,14 +514,14 @@ get_process_stat_item (int pid, int pos, int sum, MonoProcessError *error)

process_user_time += t_info.user_time.seconds + t_info.user_time.microseconds / 1e6;
process_system_time += t_info.system_time.seconds + t_info.system_time.microseconds / 1e6;

if (pos == 10 && sum == TRUE)
return (gint64)((process_user_time + process_system_time) * 10000000);
else if (pos == 10)
return (gint64)(process_user_time * 10000000);
else if (pos == 11)
return (gint64)(process_system_time * 10000000);

return 0;
#else
char buf [512];
Expand Down Expand Up @@ -604,7 +604,7 @@ get_pid_status_item (int pid, const char *item, MonoProcessError *error, int mul
{
#if defined(__APPLE__)
// ignore the multiplier

gint64 ret;
task_t task;
task_vm_info_data_t t_info;
Expand Down Expand Up @@ -661,7 +661,7 @@ get_pid_status_item (int pid, const char *item, MonoProcessError *error, int mul

if (pid != getpid ())
mach_port_deallocate (mach_task_self (), task);

return ret;
#else
char buf [64];
Expand Down Expand Up @@ -905,7 +905,7 @@ get_cpu_times (int cpu_id, gint64 *user, gint64 *systemt, gint64 *irq, gint64 *s
} else {
continue;
}

user_ticks = strtoull (data, &data, 10);
nice_ticks = strtoull (data, &data, 10);
system_ticks = strtoull (data, &data, 10);
Expand Down