Skip to content

Commit 3d3e827

Browse files
Merge pull request #394 from lplewa/update_log
Update log
2 parents 3e82a26 + 57f1905 commit 3d3e827

19 files changed

+454
-206
lines changed

benchmark/ubench.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023 Intel Corporation
3+
* Copyright (C) 2023-2024 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -44,7 +44,6 @@
4444
#define DISJOINT_POOL_MAX_POOLABLE_SIZE (2 * ALLOC_SIZE)
4545
#define DISJOINT_POOL_CAPACITY (N_ITERATIONS + 10)
4646
#define DISJOINT_POOL_MIN_BUCKET_SIZE (ALLOC_SIZE)
47-
#define DISJOINT_POOL_TRACE (0)
4847

4948
typedef struct alloc_s {
5049
void *ptr;
@@ -115,7 +114,6 @@ static umf_os_memory_provider_params_t UMF_OS_MEMORY_PROVIDER_PARAMS = {
115114
/* .numa_mode = */ UMF_NUMA_MODE_DEFAULT,
116115

117116
// others
118-
/* .traces = */ OS_MEMORY_PROVIDER_TRACE,
119117
};
120118

121119
static void *w_umfMemoryProviderAlloc(void *provider, size_t size,
@@ -237,7 +235,6 @@ UBENCH_EX(simple, disjoint_pool_with_os_memory_provider) {
237235
DISJOINT_POOL_MAX_POOLABLE_SIZE;
238236
disjoint_memory_pool_params.Capacity = DISJOINT_POOL_CAPACITY;
239237
disjoint_memory_pool_params.MinBucketSize = DISJOINT_POOL_MIN_BUCKET_SIZE;
240-
disjoint_memory_pool_params.PoolTrace = DISJOINT_POOL_TRACE;
241238

242239
umf_memory_pool_handle_t disjoint_pool;
243240
umf_result = umfPoolCreate(umfDisjointPoolOps(), os_memory_provider,

include/umf/providers/provider_os_memory.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ typedef struct umf_os_memory_provider_params_t {
7070
unsigned long maxnode;
7171
/// Describes how nodemask is interpreted
7272
umf_numa_mode_t numa_mode;
73-
74-
// others
75-
/// Log level of debug traces
76-
int traces;
7773
} umf_os_memory_provider_params_t;
7874

7975
/// @brief OS Memory Provider operation results
@@ -98,7 +94,6 @@ umfOsMemoryProviderParamsDefault(void) {
9894
NULL, /* nodemask */
9995
0, /* maxnode */
10096
UMF_NUMA_MODE_DEFAULT, /* numa_mode */
101-
0 /* traces */
10297
};
10398

10499
return params;

scripts/docs_config/introduction.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ By default, there is a guarantee that *error* messages are flushed immediately.
105105

106106
Loggers redirect messages to *stdout*, *stderr*, or a file
107107

108-
By default, no messages are printed. To enable logger you have to set **UMF_LOG** environment variable which have following syntax for setting logger options:
108+
By default, only fatal messages are printed. To enable logger you have to set **UMF_LOG** environment variable which have following syntax for setting logger options:
109109

110-
"[level:debug|info|warning|error];[flush:debug|info|warning|error];[output:stdout|stderr|file,<path>];[timestamp:yes|no];[pid:yes|no]"
110+
"[level:debug|info|warning|error|fatal];[flush:debug|info|warning|error|fatal];[output:stdout|stderr|file,<path>];[timestamp:yes|no];[pid:yes|no]"
111111

112112
* level - a log level, meaning that only messages from this level and above are printed.
113-
Possible values, from the lowest level to the highest one: *debug*, *info*, *warning*, *error*,
113+
Possible values, from the lowest level to the highest one: *debug*, *info*, *warning*, *error*, *fatal*
114114
* flush - a flush level, meaning that messages at this level and above are guaranteed to be flushed immediately,
115115
possible values are the same as above,
116116
* output - indicates where messages should be printed.

src/base_alloc/base_alloc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "base_alloc_internal.h"
1212
#include "utils_common.h"
1313
#include "utils_concurrency.h"
14+
#include "utils_log.h"
1415
#include "utils_sanitizers.h"
1516

1617
// minimum size of a single pool of the base allocator
@@ -288,7 +289,7 @@ void umf_ba_destroy(umf_ba_pool_t *pool) {
288289
#ifndef NDEBUG
289290
ba_debug_checks(pool);
290291
if (pool->metadata.n_allocs) {
291-
fprintf(stderr, "umf_ba_destroy(): pool->metadata.n_allocs = %zu\n",
292+
LOG_ERR("umf_ba_destroy(): pool->metadata.n_allocs = %zu",
292293
pool->metadata.n_allocs);
293294
assert(pool->metadata.n_allocs == 0);
294295
}

src/base_alloc/base_alloc_global.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "base_alloc_internal.h"
1717
#include "utils_common.h"
1818
#include "utils_concurrency.h"
19+
#include "utils_log.h"
1920
#include "utils_math.h"
2021
#include "utils_sanitizers.h"
2122

@@ -52,8 +53,7 @@ static void umf_ba_create_global(void) {
5253
assert(0 == (BASE_ALLOC.ac_sizes[i] & (BASE_ALLOC.ac_sizes[i] - 1)));
5354
BASE_ALLOC.ac[i] = umf_ba_create(BASE_ALLOC.ac_sizes[i]);
5455
if (!BASE_ALLOC.ac[i]) {
55-
fprintf(stderr,
56-
"base_alloc: Error. Cannot create base alloc allocation "
56+
LOG_ERR("base_alloc: Cannot create base alloc allocation "
5757
"class for size: %zu\n. Each allocation will fallback to "
5858
"allocating memory from the OS.",
5959
BASE_ALLOC.ac_sizes[i]);
@@ -163,18 +163,16 @@ void *umf_ba_global_aligned_alloc(size_t size, size_t alignment) {
163163

164164
int ac_index = size_to_idx(size);
165165
if (ac_index >= NUM_ALLOCATION_CLASSES) {
166-
// TODO: use logger here
167-
// fprintf(stderr,
168-
// "base_alloc: allocation size (%zu) larger than the biggest "
169-
// "allocation class. Falling back to OS memory allocation.\n",
170-
// size);
166+
LOG_WARN("base_alloc: allocation size (%zu) larger than the biggest "
167+
"allocation class. Falling back to OS memory allocation.",
168+
size);
171169
return add_metadata_and_align(ba_os_alloc(size), size, alignment);
172170
}
173171

174172
if (!BASE_ALLOC.ac[ac_index]) {
175173
// if creating ac failed, fall back to os allocation
176-
fprintf(stderr, "base_alloc: allocation class not created. Falling "
177-
"back to OS memory allocation.\n");
174+
LOG_WARN("base_alloc: allocation class not created. Falling "
175+
"back to OS memory allocation.");
178176
return add_metadata_and_align(ba_os_alloc(size), size, alignment);
179177
}
180178

src/base_alloc/base_alloc_linear.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "base_alloc_linear.h"
1313
#include "utils_common.h"
1414
#include "utils_concurrency.h"
15+
#include "utils_log.h"
1516

1617
#ifndef NDEBUG
1718
#define _DEBUG_EXECUTE(expression) DO_WHILE_EXPRS(expression)
@@ -249,7 +250,7 @@ void umf_ba_linear_destroy(umf_ba_linear_pool_t *pool) {
249250
#ifndef NDEBUG
250251
_DEBUG_EXECUTE(ba_debug_checks(pool));
251252
if (pool->metadata.global_n_allocs) {
252-
fprintf(stderr, "umf_ba_linear_destroy(): global_n_allocs = %zu\n",
253+
LOG_ERR("umf_ba_linear_destroy(): global_n_allocs = %zu",
253254
pool->metadata.global_n_allocs);
254255
assert(pool->metadata.global_n_allocs == 0);
255256
}

src/pool/pool_disjoint.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "../cpp_helpers.hpp"
2626
#include "pool_disjoint.h"
2727
#include "umf.h"
28+
#include "utils_log.h"
2829
#include "utils_math.h"
2930
#include "utils_sanitizers.h"
3031

@@ -433,22 +434,22 @@ Slab::~Slab() {
433434
try {
434435
unregSlab(*this);
435436
} catch (std::exception &e) {
436-
std::cerr << "DisjointPool: unexpected error: " << e.what() << "\n";
437+
LOG_ERR("DisjointPool: unexpected error: %s", e.what());
437438
}
438439

439440
try {
440441
memoryProviderFree(bucket.getMemHandle(), MemPtr);
441442
} catch (MemoryProviderError &e) {
442-
std::cerr << "DisjointPool: error from memory provider: " << e.code
443-
<< "\n";
443+
LOG_ERR("DisjointPool: error from memory provider: %d", e.code);
444+
444445
if (e.code == UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC) {
445446
const char *message = "";
446447
int error = 0;
447448

448449
umfMemoryProviderGetLastNativeError(
449450
umfGetLastFailedMemoryProvider(), &message, &error);
450-
std::cerr << "Native error msg: " << message
451-
<< ", native error code: " << error << std::endl;
451+
LOG_ERR("Native error msg: %s, native error code: %d", message,
452+
error);
452453
}
453454
}
454455
}

src/pool/pool_jemalloc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022-2023 Intel Corporation
2+
* Copyright (C) 2022-2024 Intel Corporation
33
*
44
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -13,6 +13,7 @@
1313
#include "base_alloc_global.h"
1414
#include "utils_common.h"
1515
#include "utils_concurrency.h"
16+
#include "utils_log.h"
1617
#include "utils_sanitizers.h"
1718

1819
#include <umf/memory_pool.h>
@@ -116,7 +117,7 @@ static void arena_extent_destroy(extent_hooks_t *extent_hooks, void *addr,
116117
umf_result_t ret;
117118
ret = umfMemoryProviderFree(pool->provider, addr, size);
118119
if (ret != UMF_RESULT_SUCCESS) {
119-
fprintf(stderr, "umfMemoryProviderFree failed \n");
120+
LOG_ERR("umfMemoryProviderFree failed");
120121
}
121122
}
122123

@@ -138,7 +139,7 @@ static bool arena_extent_dalloc(extent_hooks_t *extent_hooks, void *addr,
138139
umf_result_t ret;
139140
ret = umfMemoryProviderFree(pool->provider, addr, size);
140141
if (ret != UMF_RESULT_SUCCESS) {
141-
fprintf(stderr, "umfMemoryProviderFree failed in dalloc \n");
142+
LOG_ERR("umfMemoryProviderFree failed in dalloc");
142143
}
143144

144145
return ret != UMF_RESULT_SUCCESS;
@@ -405,7 +406,7 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
405406
err = je_mallctl("arenas.create", (void *)&arena_index, &unsigned_size,
406407
NULL, 0);
407408
if (err) {
408-
fprintf(stderr, "Could not create arena.\n");
409+
LOG_ERR("Could not create arena.");
409410
goto err_free_pool;
410411
}
411412

@@ -416,8 +417,7 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
416417
if (err) {
417418
snprintf(cmd, sizeof(cmd), "arena.%u.destroy", arena_index);
418419
je_mallctl(cmd, NULL, 0, NULL, 0);
419-
fprintf(stderr,
420-
"Could not setup extent_hooks for newly created arena.\n");
420+
LOG_ERR("Could not setup extent_hooks for newly created arena.");
421421
goto err_free_pool;
422422
}
423423

src/pool/pool_scalable.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "utils_common.h"
2525
#include "utils_concurrency.h"
2626
#include "utils_load_library.h"
27+
#include "utils_log.h"
2728
#include "utils_sanitizers.h"
2829

2930
typedef void *(*raw_alloc_tbb_type)(intptr_t, size_t *);
@@ -109,7 +110,7 @@ static int init_tbb_callbacks(tbb_callbacks_t *tbb_callbacks) {
109110
const char *lib_name = tbb_symbol[TBB_LIB_NAME];
110111
tbb_callbacks->lib_handle = util_open_library(lib_name);
111112
if (!tbb_callbacks->lib_handle) {
112-
fprintf(stderr, "%s not found.\n", lib_name);
113+
LOG_ERR("%s not found.", lib_name);
113114
return -1;
114115
}
115116

@@ -134,7 +135,7 @@ static int init_tbb_callbacks(tbb_callbacks_t *tbb_callbacks) {
134135
!tbb_callbacks->pool_aligned_malloc || !tbb_callbacks->pool_free ||
135136
!tbb_callbacks->pool_create_v1 || !tbb_callbacks->pool_destroy ||
136137
!tbb_callbacks->pool_identify) {
137-
fprintf(stderr, "Could not find symbols in %s.\n", lib_name);
138+
LOG_ERR("Could not find symbols in %s", lib_name);
138139
util_close_library(tbb_callbacks->lib_handle);
139140
return -1;
140141
}
@@ -160,10 +161,8 @@ static void tbb_raw_free_wrapper(intptr_t pool_id, void *ptr, size_t bytes) {
160161
umf_result_t ret = umfMemoryProviderFree(pool->mem_provider, ptr, bytes);
161162
if (ret != UMF_RESULT_SUCCESS) {
162163
TLS_last_free_error = ret;
163-
fprintf(
164-
stderr,
165-
"Memory provider failed to free memory, addr = %p, size = %zu\n",
166-
ptr, bytes);
164+
LOG_ERR("Memory provider failed to free memory, addr = %p, size = %zu",
165+
ptr, bytes);
167166
}
168167
}
169168

@@ -183,13 +182,13 @@ static umf_result_t tbb_pool_initialize(umf_memory_provider_handle_t provider,
183182
tbb_memory_pool_t *pool_data =
184183
umf_ba_global_alloc(sizeof(tbb_memory_pool_t));
185184
if (!pool_data) {
186-
fprintf(stderr, "cannot allocate memory for metadata\n");
185+
LOG_ERR("cannot allocate memory for metadata");
187186
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
188187
}
189188

190189
int ret = init_tbb_callbacks(&pool_data->tbb_callbacks);
191190
if (ret != 0) {
192-
fprintf(stderr, "loading TBB symbols failed\n");
191+
LOG_ERR("loading TBB symbols failed");
193192
return UMF_RESULT_ERROR_UNKNOWN;
194193
}
195194

src/provider/provider_level_zero.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "utils_common.h"
2121
#include "utils_concurrency.h"
2222
#include "utils_load_library.h"
23+
#include "utils_log.h"
2324
#include "utils_sanitizers.h"
2425

2526
typedef struct ze_memory_provider_t {
@@ -59,7 +60,7 @@ static void init_ze_global_state(void) {
5960

6061
if (!g_ze_ops.zeMemAllocHost || !g_ze_ops.zeMemAllocDevice ||
6162
!g_ze_ops.zeMemAllocShared || !g_ze_ops.zeMemFree) {
62-
fprintf(stderr, "Required Level Zero symbols not found.\n");
63+
LOG_ERR("Required Level Zero symbols not found.");
6364
Init_ze_global_state_failed = true;
6465
}
6566
}
@@ -74,7 +75,7 @@ enum umf_result_t ze_memory_provider_initialize(void *params, void **provider) {
7475

7576
util_init_once(&ze_is_initialized, init_ze_global_state);
7677
if (Init_ze_global_state_failed) {
77-
fprintf(stderr, "Loading Level Zero symbols failed\n");
78+
LOG_ERR("Loading Level Zero symbols failed");
7879
return UMF_RESULT_ERROR_UNKNOWN;
7980
}
8081

0 commit comments

Comments
 (0)