modules-common.c 874 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Common Primitives for DAMON Modules
  4. *
  5. * Author: SeongJae Park <sj@kernel.org>
  6. */
  7. #include <linux/damon.h>
  8. #include "modules-common.h"
  9. /*
  10. * Allocate, set, and return a DAMON context for the physical address space.
  11. * @ctxp: Pointer to save the point to the newly created context
  12. * @targetp: Pointer to save the point to the newly created target
  13. */
  14. int damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp,
  15. struct damon_target **targetp)
  16. {
  17. struct damon_ctx *ctx;
  18. struct damon_target *target;
  19. ctx = damon_new_ctx();
  20. if (!ctx)
  21. return -ENOMEM;
  22. if (damon_select_ops(ctx, DAMON_OPS_PADDR)) {
  23. damon_destroy_ctx(ctx);
  24. return -EINVAL;
  25. }
  26. target = damon_new_target();
  27. if (!target) {
  28. damon_destroy_ctx(ctx);
  29. return -ENOMEM;
  30. }
  31. damon_add_target(ctx, target);
  32. *ctxp = ctx;
  33. *targetp = target;
  34. return 0;
  35. }