Commit 96367750 authored by Jens Korinth's avatar Jens Korinth
Browse files

Bugfixes in performance counter file handling

* libplatform now automatically logs the contents of perf when
  destroying the device
* fixed awkward platform_destroy_device: can be destroyed by
  pointer now, not only id
parent b81c349e
......@@ -10,6 +10,7 @@ platform_res_t platform_enum_devices(platform_ctx_t *ctx, size_t *num_devices,
platform_device_info_t **devs);
platform_res_t platform_create_device(platform_ctx_t *ctx, platform_devctx_t **pdctx,
platform_dev_id_t const dev_id, platform_access_t const mode);
void platform_destroy_device(platform_ctx_t *ctx, platform_dev_id_t const dev_id);
void platform_destroy_device(platform_ctx_t *ctx, platform_devctx_t *pdctx);
void platform_destroy_device_by_id(platform_ctx_t *ctx, platform_dev_id_t const dev_id);
#endif /* PLATFORM_CTX_H__ */
......@@ -6,10 +6,10 @@
#include <tlkm_device_ioctl_cmds.h>
#include "platform_types.h"
#define PLATFORM_DEVFILE_MAXLEN 16
#define PLATFORM_DEVFILE_MAXLEN 32
#define TLKM_CONTROL_FN "/dev/" TLKM_IOCTL_FN
#define TLKM_DEV_CONTROL_FN "/dev/" TLKM_DEV_IOCTL_FN
#define TLKM_PERFC_FN "/dev/tlkm_perfc"
#define TLKM_PERFC_FN "/dev/" TLKM_DEV_PERFC_FN
static inline
char *control_file(platform_dev_id_t const dev_id)
......@@ -20,4 +20,15 @@ char *control_file(platform_dev_id_t const dev_id)
return fn;
}
#ifndef NPERFC
static inline
char *perfc_file(platform_dev_id_t const dev_id)
{
char *fn = (char *)calloc(sizeof(*fn), PLATFORM_DEVFILE_MAXLEN);
if (fn)
snprintf(fn, PLATFORM_DEVFILE_MAXLEN, TLKM_PERFC_FN, dev_id);
return fn;
}
#endif
#endif /* PLATFORM_DEVFILES_H__ */
......@@ -12,9 +12,6 @@
struct platform_ctx {
int fd_tlkm;
#ifndef NPERFC
int fd_perfc;
#endif
size_t num_devs;
platform_device_info_t devs[PLATFORM_MAX_DEVS];
char version[TLKM_VERSION_SZ];
......@@ -74,15 +71,6 @@ platform_res_t init_platform(platform_ctx_t *ctx)
r = PERR_TLKM_ERROR;
goto err_tlkm;
}
#ifndef NPERFC
ctx->fd_perfc = open(TLKM_PERFC_FN, O_RDONLY);
if (ctx->fd_perfc == -1) {
ERR("could not open " TLKM_PERFC_FN ": %s (%d)", strerror(errno), errno);
r = PERR_TLKM_ERROR;
goto err_perfc;
}
#endif
if (get_tlkm_version(ctx, ctx->version)) goto err_ioctl;
LOG(LPLL_TLKM, "TLKM version: %s", ctx->version);
......@@ -103,10 +91,6 @@ platform_res_t init_platform(platform_ctx_t *ctx)
return r;
err_ioctl:
#ifndef NPERFC
close(ctx->fd_perfc);
err_perfc:
#endif
close(ctx->fd_tlkm);
err_tlkm:
return r;
......@@ -115,9 +99,6 @@ err_tlkm:
static
void deinit_platform(platform_ctx_t *ctx)
{
#ifndef NPERFC
close(ctx->fd_perfc);
#endif
close(ctx->fd_tlkm);
LOG(LPLL_INIT, "platform deinited");
}
......@@ -209,7 +190,7 @@ err_pdev:
return res;
}
void platform_destroy_device(platform_ctx_t *ctx, platform_dev_id_t const dev_id)
void platform_destroy_device_by_id(platform_ctx_t *ctx, platform_dev_id_t const dev_id)
{
assert(dev_id < PLATFORM_MAX_DEVS);
assert(ctx);
......@@ -230,3 +211,9 @@ void platform_destroy_device(platform_ctx_t *ctx, platform_dev_id_t const dev_id
LOG(LPLL_DEVICE, "device #%03u destroyed", dev_id);
}
}
void platform_destroy_device(platform_ctx_t *ctx, platform_devctx_t *pdctx)
{
assert(pdctx);
platform_destroy_device_by_id(ctx, pdctx->dev_id);
}
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
......@@ -81,6 +82,7 @@ platform_res_t platform_devctx_init(platform_ctx_t *ctx,
DEVLOG(dev_id, LPLL_INIT, "context initialization finished");
return PLATFORM_SUCCESS;
zynq_exit(devctx);
err_platform:
platform_signaling_deinit(devctx->signaling);
err_signaling:
......@@ -91,9 +93,31 @@ err_info:
return res;
}
static inline
void log_perfc(platform_devctx_t *devctx)
{
#ifndef NPERFC
#define BUFSZ (1 << 12)
char *fn = perfc_file(devctx->dev_id);
char *buf = (char *)calloc(sizeof(*buf), BUFSZ);
FILE *fp = fopen(fn, "r");
size_t n = BUFSZ;
if (fp) {
while (getline(&buf, &n, fp) > 0) {
buf[strcspn(buf, "\r\n")] = '\0';
DEVLOG(devctx->dev_id, LPLL_DEVICE, "%s", buf);
}
fclose(fp);
}
free(buf);
free(fn);
#endif
}
void platform_devctx_deinit(platform_devctx_t *devctx)
{
if (devctx) {
log_perfc(devctx);
zynq_exit(devctx);
platform_dev_id_t dev_id = devctx->dev_id;
DEVLOG(dev_id, LPLL_INIT, "destroying platform signaling ...");
......
......@@ -131,9 +131,16 @@ platform_res_t platform_create_device(platform_ctx_t *ctx,
/**
* Destroy the given device context and release the selected device.
* @param ctx platform context
* @param devctx device context to destroy
* @param pdctx device context to destroy
**/
void platform_destroy_device(platform_ctx_t *ctx, platform_dev_id_t const dev_id);
void platform_destroy_device(platform_ctx_t *ctx, platform_devctx_t *pdctx);
/**
* Destroy the given device context and release the selected device.
* @param ctx platform context
* @param dev_id device id
**/
void platform_destroy_device_by_id(platform_ctx_t *ctx, platform_dev_id_t const dev_id);
/** Retrieves an info struct from the hardware. **/
platform_res_t platform_info(platform_devctx_t const *ctx, platform_info_t *info);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment