Lines Matching refs:ctx

91  * @ctx:	monitoring context to use the operations.
95 * @ctx to use it.
99 int damon_select_ops(struct damon_ctx *ctx, enum damon_ops_id id)
110 ctx->ops = damon_registered_ops[id];
337 void damon_add_scheme(struct damon_ctx *ctx, struct damos *s)
339 list_add_tail(&s->list, &ctx->schemes);
383 void damon_add_target(struct damon_ctx *ctx, struct damon_target *t)
385 list_add_tail(&t->list, &ctx->adaptive_targets);
388 bool damon_targets_empty(struct damon_ctx *ctx)
390 return list_empty(&ctx->adaptive_targets);
420 struct damon_ctx *ctx;
422 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
423 if (!ctx)
426 init_completion(&ctx->kdamond_started);
428 ctx->attrs.sample_interval = 5 * 1000;
429 ctx->attrs.aggr_interval = 100 * 1000;
430 ctx->attrs.ops_update_interval = 60 * 1000 * 1000;
432 ctx->passed_sample_intervals = 0;
434 ctx->next_aggregation_sis = 0;
435 ctx->next_ops_update_sis = 0;
437 mutex_init(&ctx->kdamond_lock);
439 ctx->attrs.min_nr_regions = 10;
440 ctx->attrs.max_nr_regions = 1000;
442 INIT_LIST_HEAD(&ctx->adaptive_targets);
443 INIT_LIST_HEAD(&ctx->schemes);
445 return ctx;
448 static void damon_destroy_targets(struct damon_ctx *ctx)
452 if (ctx->ops.cleanup) {
453 ctx->ops.cleanup(ctx);
457 damon_for_each_target_safe(t, next_t, ctx)
461 void damon_destroy_ctx(struct damon_ctx *ctx)
465 damon_destroy_targets(ctx);
467 damon_for_each_scheme_safe(s, next_s, ctx)
470 kfree(ctx);
518 static void damon_update_monitoring_results(struct damon_ctx *ctx,
521 struct damon_attrs *old_attrs = &ctx->attrs;
531 damon_for_each_target(t, ctx)
539 * @ctx: monitoring context
547 int damon_set_attrs(struct damon_ctx *ctx, struct damon_attrs *attrs)
559 ctx->next_aggregation_sis = ctx->passed_sample_intervals +
561 ctx->next_ops_update_sis = ctx->passed_sample_intervals +
564 damon_update_monitoring_results(ctx, attrs);
565 ctx->attrs = *attrs;
571 * @ctx: monitoring context
578 void damon_set_schemes(struct damon_ctx *ctx, struct damos **schemes,
584 damon_for_each_scheme_safe(s, next, ctx)
587 damon_add_scheme(ctx, schemes[i]);
605 static unsigned long damon_region_sz_limit(struct damon_ctx *ctx)
611 damon_for_each_target(t, ctx) {
616 if (ctx->attrs.min_nr_regions)
617 sz /= ctx->attrs.min_nr_regions;
628 * @ctx: monitoring context
634 static int __damon_start(struct damon_ctx *ctx)
638 mutex_lock(&ctx->kdamond_lock);
639 if (!ctx->kdamond) {
641 reinit_completion(&ctx->kdamond_started);
642 ctx->kdamond = kthread_run(kdamond_fn, ctx, "kdamond.%d",
644 if (IS_ERR(ctx->kdamond)) {
645 err = PTR_ERR(ctx->kdamond);
646 ctx->kdamond = NULL;
648 wait_for_completion(&ctx->kdamond_started);
651 mutex_unlock(&ctx->kdamond_lock);
698 * @ctx: monitoring context
702 static int __damon_stop(struct damon_ctx *ctx)
706 mutex_lock(&ctx->kdamond_lock);
707 tsk = ctx->kdamond;
710 mutex_unlock(&ctx->kdamond_lock);
715 mutex_unlock(&ctx->kdamond_lock);
858 static bool __damos_filter_out(struct damon_ctx *ctx, struct damon_target *t,
868 damon_for_each_target(ti, ctx) {
906 static bool damos_filter_out(struct damon_ctx *ctx, struct damon_target *t,
912 if (__damos_filter_out(ctx, t, r, filter))
1196 static void kdamond_split_regions(struct damon_ctx *ctx)
1203 damon_for_each_target(t, ctx)
1206 if (nr_regions > ctx->attrs.max_nr_regions / 2)
1211 nr_regions < ctx->attrs.max_nr_regions / 3)
1214 damon_for_each_target(t, ctx)
1228 static bool kdamond_need_stop(struct damon_ctx *ctx)
1235 if (!ctx->ops.target_valid)
1238 damon_for_each_target(t, ctx) {
1239 if (ctx->ops.target_valid(t))
1304 static int kdamond_wait_activation(struct damon_ctx *ctx)
1311 while (!kdamond_need_stop(ctx)) {
1312 damon_for_each_scheme(s, ctx) {
1324 if (ctx->callback.after_wmarks_check &&
1325 ctx->callback.after_wmarks_check(ctx))
1331 static void kdamond_init_intervals_sis(struct damon_ctx *ctx)
1333 unsigned long sample_interval = ctx->attrs.sample_interval ?
1334 ctx->attrs.sample_interval : 1;
1336 ctx->passed_sample_intervals = 0;
1337 ctx->next_aggregation_sis = ctx->attrs.aggr_interval / sample_interval;
1338 ctx->next_ops_update_sis = ctx->attrs.ops_update_interval /
1347 struct damon_ctx *ctx = data;
1355 complete(&ctx->kdamond_started);
1356 kdamond_init_intervals_sis(ctx);
1358 if (ctx->ops.init)
1359 ctx->ops.init(ctx);
1360 if (ctx->callback.before_start && ctx->callback.before_start(ctx))
1363 sz_limit = damon_region_sz_limit(ctx);
1365 while (!kdamond_need_stop(ctx)) {
1367 * ctx->attrs and ctx->next_{aggregation,ops_update}_sis could
1373 unsigned long next_aggregation_sis = ctx->next_aggregation_sis;
1374 unsigned long next_ops_update_sis = ctx->next_ops_update_sis;
1375 unsigned long sample_interval = ctx->attrs.sample_interval;
1377 if (kdamond_wait_activation(ctx))
1380 if (ctx->ops.prepare_access_checks)
1381 ctx->ops.prepare_access_checks(ctx);
1382 if (ctx->callback.after_sampling &&
1383 ctx->callback.after_sampling(ctx))
1387 ctx->passed_sample_intervals++;
1389 if (ctx->ops.check_accesses)
1390 max_nr_accesses = ctx->ops.check_accesses(ctx);
1392 sample_interval = ctx->attrs.sample_interval ?
1393 ctx->attrs.sample_interval : 1;
1394 if (ctx->passed_sample_intervals == next_aggregation_sis) {
1395 ctx->next_aggregation_sis = next_aggregation_sis +
1396 ctx->attrs.aggr_interval / sample_interval;
1397 kdamond_merge_regions(ctx,
1400 if (ctx->callback.after_aggregation &&
1401 ctx->callback.after_aggregation(ctx))
1403 if (!list_empty(&ctx->schemes))
1404 kdamond_apply_schemes(ctx);
1405 kdamond_reset_aggregated(ctx);
1406 kdamond_split_regions(ctx);
1407 if (ctx->ops.reset_aggregated)
1408 ctx->ops.reset_aggregated(ctx);
1411 if (ctx->passed_sample_intervals == next_ops_update_sis) {
1412 ctx->next_ops_update_sis = next_ops_update_sis +
1413 ctx->attrs.ops_update_interval /
1415 if (ctx->ops.update)
1416 ctx->ops.update(ctx);
1417 sz_limit = damon_region_sz_limit(ctx);
1421 damon_for_each_target(t, ctx) {
1426 if (ctx->callback.before_terminate)
1427 ctx->callback.before_terminate(ctx);
1428 if (ctx->ops.cleanup)
1429 ctx->ops.cleanup(ctx);
1432 mutex_lock(&ctx->kdamond_lock);
1433 ctx->kdamond = NULL;
1434 mutex_unlock(&ctx->kdamond_lock);