Skip to content

Commit 5c8cdf6

Browse files
committed
Fix suppressed error messages & tracing during open
Some error & trace messages called during ocxl_afu_open_*() were not emitted as they were checking the per-AFU error & tracing switches (which could never be enabled at that point), rather than the global ones. Signed-off-by: Alastair D'Silva <alastair@d-silva.org>
1 parent e0d1aa1 commit 5c8cdf6

2 files changed

Lines changed: 23 additions & 18 deletions

File tree

src/afu.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,15 @@ static bool populate_metadata(dev_t dev, ocxl_afu *afu)
396396
*/
397397
static void trace_metadata(ocxl_afu *afu)
398398
{
399-
TRACE(afu, "device path=\"%s\"", afu->device_path);
400-
TRACE(afu, "sysfs path=\"%s\"", afu->sysfs_path);
401-
TRACE(afu, "AFU Name=\"%s\"", afu->identifier.afu_name);
402-
TRACE(afu, "AFU Index=%u", afu->identifier.afu_index);
403-
TRACE(afu, "AFU Version=%u:%u", afu->version_major, afu->version_minor);
404-
TRACE(afu, "Global MMIO size=%llu", afu->global_mmio.length);
405-
TRACE(afu, "Per PASID MMIO size=%llu", afu->per_pasid_mmio.length);
406-
TRACE(afu, "Page Size=%llu", afu->page_size);
407-
TRACE(afu, "PASID=%lu", afu->pasid);
399+
TRACE_OPEN("device path=\"%s\"", afu->device_path);
400+
TRACE_OPEN("sysfs path=\"%s\"", afu->sysfs_path);
401+
TRACE_OPEN("AFU Name=\"%s\"", afu->identifier.afu_name);
402+
TRACE_OPEN("AFU Index=%u", afu->identifier.afu_index);
403+
TRACE_OPEN("AFU Version=%u:%u", afu->version_major, afu->version_minor);
404+
TRACE_OPEN("Global MMIO size=%llu", afu->global_mmio.length);
405+
TRACE_OPEN("Per PASID MMIO size=%llu", afu->per_pasid_mmio.length);
406+
TRACE_OPEN("Page Size=%llu", afu->page_size);
407+
TRACE_OPEN("PASID=%lu", afu->pasid);
408408
}
409409

410410
/**
@@ -429,28 +429,28 @@ static ocxl_err afu_open(ocxl_afu *afu)
429429
if (fd < 0) {
430430
if (errno == ENOSPC) {
431431
rc = OCXL_NO_MORE_CONTEXTS;
432-
errmsg(afu, rc, "Could not open AFU device '%s', the maximum number of contexts has been reached: Error %d: %s",
432+
errmsg(NULL, rc, "Could not open AFU device '%s', the maximum number of contexts has been reached: Error %d: %s",
433433
afu->device_path, errno, strerror(errno));
434434
return rc;
435435
}
436436

437437
rc = OCXL_NO_DEV;
438-
errmsg(afu, rc, "Could not open AFU device '%s': Error %d: %s", afu->device_path, errno, strerror(errno));
438+
errmsg(NULL, rc, "Could not open AFU device '%s': Error %d: %s", afu->device_path, errno, strerror(errno));
439439
return rc;
440440
}
441441

442442
afu->fd = fd;
443443

444444
rc = global_mmio_open(afu);
445445
if (rc != OCXL_OK) {
446-
errmsg(afu, rc, "Could not open global MMIO descriptor");
446+
errmsg(NULL, rc, "Could not open global MMIO descriptor");
447447
return rc;
448448
}
449449

450450
fd = epoll_create1(EPOLL_CLOEXEC);
451451
if (fd < 0) {
452452
ocxl_err rc = OCXL_NO_DEV;
453-
errmsg(afu, rc, "Could not create epoll descriptor. Error %d: %s",
453+
errmsg(NULL, rc, "Could not create epoll descriptor. Error %d: %s",
454454
errno, strerror(errno));
455455
return rc;
456456
}
@@ -461,15 +461,15 @@ static ocxl_err afu_open(ocxl_afu *afu)
461461
ev.data.ptr = &afu->fd_info; // Already set up in afu_init
462462
if (epoll_ctl(afu->epoll_fd, EPOLL_CTL_ADD, afu->fd, &ev) == -1) {
463463
ocxl_err rc = OCXL_NO_DEV;
464-
errmsg(afu, rc, "Could not add device fd %d to epoll fd %d: %d: '%s'",
464+
errmsg(NULL, rc, "Could not add device fd %d to epoll fd %d: %d: '%s'",
465465
afu->fd, afu->epoll_fd, errno, strerror(errno));
466466
return rc;
467467
}
468468

469469
struct ocxl_ioctl_metadata metadata;
470470
if (ioctl(afu->fd, OCXL_IOCTL_GET_METADATA, &metadata)) {
471471
ocxl_err rc = OCXL_NO_DEV;
472-
errmsg(afu, rc, "OCXL_IOCTL_GET_METADATA failed %d:%s", errno, strerror(errno));
472+
errmsg(NULL, rc, "OCXL_IOCTL_GET_METADATA failed %d:%s", errno, strerror(errno));
473473
return rc;
474474
}
475475

@@ -480,9 +480,7 @@ static ocxl_err afu_open(ocxl_afu *afu)
480480
afu->global_mmio.length = metadata.global_mmio_size;
481481
afu->pasid = metadata.pasid;
482482

483-
if (afu->tracing) {
484-
trace_metadata(afu);
485-
}
483+
trace_metadata(afu);
486484

487485
return OCXL_OK;
488486
}

src/libocxl_internal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ do {\
5353
} \
5454
} while (0)
5555

56+
#define TRACE_OPEN(__trc_format, __trc_args...) \
57+
do {\
58+
if (UNLIKELY(tracing)) { \
59+
trace_message("Trace", __FILE__, __LINE__, __FUNCTION__, __trc_format, ## __trc_args); \
60+
} \
61+
} while (0)
62+
5663
extern bool verbose_errors;
5764
extern bool tracing;
5865
extern void (*error_handler)(ocxl_err error, const char *message);

0 commit comments

Comments
 (0)