Skip to content

Commit

Permalink
Add cpu information to the console benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
psyrykh committed Jul 28, 2022
1 parent 55df837 commit 85fdcc8
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 19 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf

cmake-build-*/
release/
.idea/
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.0
2.1.1
10 changes: 6 additions & 4 deletions cmake/compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,25 @@
message(STATUS "Configuring compiler:")

set(CMAKE_C_STANDARD 90)
set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")

if (NOT MSVC)
set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
endif ()

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "MinSizeRel")
elseif (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
if (MSVC)
# warning level 4 and all warnings as errors
# warning level 4
string(REGEX REPLACE "/W." "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
set(CMAKE_C_FLAGS "/W4 /WX ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "/W4 ${CMAKE_C_FLAGS}")
else ()
# lots of warnings and all warnings as errors
set(CMAKE_C_FLAGS "-Wall -Wextra -Werror ${CMAKE_C_FLAGS} ")
endif ()
add_compile_definitions(LFK_RUNFAST)
endif ()


if (MSVC)
execute_process(COMMAND ${CMAKE_C_COMPILER} ERROR_VARIABLE COMPILER_VERSION OUTPUT_QUIET)
else ()
Expand Down
6 changes: 6 additions & 0 deletions cmake/definitions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ else ()
message(FATAL "Unsupported target host system name ${CMAKE_SYSTEM_NAME}")
endif ()

message(STATUS "CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}")
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(x86_64|x86|AMD64)$" AND NOT ("${CMAKE_OSX_ARCHITECTURES}" MATCHES "arm"))
set(LFK_USE_CPUID ON)
add_compile_definitions(LFK_USE_CPUID)
endif ()

add_compile_definitions(LFK_VERSION="${LFK_VERSION}")
add_compile_definitions(LFK_COMPILER="${CMAKE_C_COMPILER_VERSION}")

Expand Down
2 changes: 2 additions & 0 deletions lfk_benchmark/inc/lfk/lfk.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ const char *benchmark_get_compiler_info(benchmark_handler_t handler);

const char *benchmark_get_date(benchmark_handler_t handler);

const char *benchmark_get_cpu_name(benchmark_handler_t handler);

const lfk_full_result_t *benchmark_get_results(benchmark_handler_t handler);

unsigned int benchmark_get_core_count(benchmark_handler_t handler);
Expand Down
16 changes: 14 additions & 2 deletions lfk_benchmark/src/lfk.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "string.h"
#include "time.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "platform.h"
#include "thread.h"
Expand All @@ -46,6 +46,7 @@ typedef struct benchmark_handler_ {
char *compiler_info;
char *version_info;
char *timestamp;
char *cpu_name;

lfk_full_result_t result;

Expand All @@ -67,6 +68,10 @@ static void benchmark_fill_timestamp(benchmark_handler_t handler) {
handler->timestamp = strdup(buffer);
}

static void benchmark_fill_cpu_name(benchmark_handler_t handler) {
handler->cpu_name = get_cpu_name();
}

benchmark_handler_t benchmark_init() {
benchmark_handler_t ret = calloc(1, sizeof(benchmark_handler_));

Expand All @@ -80,6 +85,8 @@ benchmark_handler_t benchmark_init() {
ret->compiler_info = strdup(LFK_COMPILER);

benchmark_fill_timestamp(ret);
benchmark_fill_cpu_name(ret);
benchmark_set_core_count(ret, 0);

return ret;
}
Expand All @@ -88,6 +95,7 @@ void benchmark_cleanup(benchmark_handler_t handler) {
free(handler->version_info);
free(handler->compiler_info);
free(handler->timestamp);
free(handler->cpu_name);
free(handler);
}

Expand Down Expand Up @@ -254,6 +262,10 @@ const char *benchmark_get_date(benchmark_handler_t handler) {
return handler->timestamp;
}

const char *benchmark_get_cpu_name(benchmark_handler_t handler) {
return handler->cpu_name;
}

const lfk_full_result_t *benchmark_get_results(benchmark_handler_t handler) {
return &handler->result;
}
1 change: 1 addition & 0 deletions lfk_benchmark/src/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
#define LFKX_LFK_CORE_PLATFORM_H

unsigned get_core_count();
char *get_cpu_name();

#endif /* LFKX_LFK_CORE_PLATFORM_H */
28 changes: 28 additions & 0 deletions lfk_benchmark/src/posix/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,34 @@
*/

#include "platform.h"
#include <string.h>
#include <unistd.h>

#ifdef LFK_USE_CPUID
#include <cpuid.h>
#endif

unsigned get_core_count() { return (int)sysconf(_SC_NPROCESSORS_ONLN); }

char *get_cpu_name() {
#if defined(LFK_USE_CPUID)
unsigned int brand[12];
if (!__get_cpuid_max(0x80000004, NULL)) {
return strdup("No CPUID information");
}

__get_cpuid(0x80000002, brand + 0x0, brand + 0x1, brand + 0x2, brand + 0x3);
__get_cpuid(0x80000003, brand + 0x4, brand + 0x5, brand + 0x6, brand + 0x7);
__get_cpuid(0x80000004, brand + 0x8, brand + 0x9, brand + 0xa, brand + 0xb);

// remove trailing whitespaces
char *ret = (char *)brand;
while (' ' == *ret) {
ret++;
}

return strdup((char *)brand);
#else
return strdup("No CPUID information");
#endif
}
22 changes: 20 additions & 2 deletions lfk_benchmark/src/win/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,29 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <windows.h>

#include "platform.h"
#include "windows.h"

#ifdef LFK_USE_CPUID
#include <intrin.h>
#endif

char *get_cpu_name() {
#ifdef LFK_USE_CPUID
int brand[12];
__cpuid(&brand[0], 0x80000002);
__cpuid(&brand[4], 0x80000003);
__cpuid(&brand[8], 0x80000004);
return strdup((char *)brand);
#else
return strdup("No CPUID information");
#endif
}

unsigned get_core_count() {
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
return (int)sysinfo.dwNumberOfProcessors;
}
}

4 changes: 2 additions & 2 deletions lfk_benchmark/src/win/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

#include "thread.h"

#include "stdlib.h"
#include "windows.h"
#include <stdlib.h>
#include <windows.h>

typedef struct lfk_thread_handler_t {
HANDLE thread_handler;
Expand Down
18 changes: 11 additions & 7 deletions lfk_console/src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int app_parse_args(program_parameters_t *params, int argc,
params->html_report_file = "lfk-report.html";

#ifdef LFK_RUNFAST
params->execution_time = 0.1;
params->execution_time = 0.01;
#endif

for (i = 1; i < argc; i++) {
Expand Down Expand Up @@ -118,12 +118,17 @@ int app_parse_args(program_parameters_t *params, int argc,
return 0;
}

void app_print_run_parameters(const program_parameters_t *params) {
void app_print_run_parameters(const program_parameters_t *params,
const benchmark_handler_t handler) {
printf("Running parameters:\n");
printf("Report html file: ............. %s\n", params->html_report_file);
printf("Report text file: ............. %s\n", params->text_report_file);
printf("Core count (0 = auto): ........ %i\n", params->core_count);
printf("Execution time per kernel: .... %f second(s)\n",
printf("CPU: .......................... %s\n",
benchmark_get_cpu_name(handler));
printf("Core count: ................... %i%s\n",
benchmark_get_core_count(handler),
(params->core_count == 0) ? " (auto)" : "");
printf("Execution time per kernel: .... %.1f second(s)\n",
params->execution_time);
}

Expand All @@ -133,18 +138,17 @@ int app_main(const int argc, const char *const argv[]) {
benchmark_progress_callback_handler_t callbackHandler;

app_parse_args(&params, argc, argv);
app_print_run_parameters(&params);

handler = benchmark_init();
benchmark_set_execution_time(handler, params.execution_time);

benchmark_set_core_count(handler, params.core_count);

callbackHandler.data = NULL;
callbackHandler.callback = benchmark_callback;

benchmark_set_progress_callback(handler, callbackHandler);

app_print_run_parameters(&params, handler);

benchmark_run(handler);
printf("\n");

Expand Down
2 changes: 2 additions & 0 deletions lfk_console/src/utils/html_report_generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ static char *create_system_param_table(const benchmark_handler_t result_p) {
benchmark_get_date(result_p));
len += snprintf(buffer + len, 10240 - len, format, "Compiler",
benchmark_get_compiler_info(result_p));
len += snprintf(buffer + len, 10240 - len, format, "CPU name",
benchmark_get_cpu_name(result_p));
len += snprintf(buffer + len, 10240 - len, format, "Core count",
core_count_as_char);
len += snprintf(buffer + len, 10240 - len, format, " ", " ");
Expand Down
1 change: 1 addition & 0 deletions lfk_console/src/utils/text_report_generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void text_report_generator_create_report(benchmark_handler_t handler,
fprintf(file_handler, "Date - %s\n", benchmark_get_date(handler));
fprintf(file_handler, "Compiler - %s\n",
benchmark_get_compiler_info(handler));
fprintf(file_handler, "CPU name - %s\n", benchmark_get_cpu_name(handler));
fprintf(file_handler, "Core count - %u\n", benchmark_get_core_count(handler));
fprintf(file_handler, "\n");
fprintf(file_handler, "SINGLECORE RESULT - %f\n", result->singlecore_result);
Expand Down
1 change: 1 addition & 0 deletions tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

G_EXECUTABLE=$(basename $0)
G_BASE_DIR=$(dirname $(realpath $0))

Expand Down
22 changes: 21 additions & 1 deletion tools/common.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
#!/bin/bash
# Copyright (c) 2022 Waverian
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

function fail_with()
{
Expand Down Expand Up @@ -95,7 +115,7 @@ function build() {
local EXECUTABLE_NAME=$(echo "lfk-benchmark_${G_VERSION_MAJOR}-${G_VERSION_MINOR}-${G_VERSION_PATCH}_$(basename ${BUILD_DIR})" | tr '/' '-' )
cp ${BUILD_DIR}/lfk_console/lfk-console ${G_RELEASE_DIR}/${EXECUTABLE_NAME} 2> /dev/null || \
cp ${BUILD_DIR}/lfk_console/lfk-console.exe ${G_RELEASE_DIR}/${EXECUTABLE_NAME}.exe 2> /dev/null || \
fail_with "lfk-console./ge /lfk-console executable was not created"
fail_with "lfk-console./exe /lfk-console executable was not created"

rm -rf ${BUILD_DIR}
}
Expand Down
1 change: 1 addition & 0 deletions tools/generate_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

G_EXECUTABLE=$(basename $0)
G_BASE_DIR=$(dirname $(realpath $0))

Expand Down

0 comments on commit 85fdcc8

Please sign in to comment.