1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (C) 2019-2022 Red Hat, Inc. Daniel Bristot de Oliveira <bristot@kernel.org> 4 * 5 * Deterministic automata (DA) monitor functions, to be used together 6 * with automata models in C generated by the rvgen tool. 7 * 8 * The rvgen tool is available at tools/verification/rvgen/ 9 * 10 * For further information, see: 11 * Documentation/trace/rv/monitor_synthesis.rst 12 */ 13 14 #ifndef _RV_DA_MONITOR_H 15 #define _RV_DA_MONITOR_H 16 17 #include <rv/automata.h> 18 #include <linux/rv.h> 19 #include <linux/stringify.h> 20 #include <linux/bug.h> 21 #include <linux/sched.h> 22 #include <linux/slab.h> 23 #include <linux/hashtable.h> 24 25 /* 26 * Per-cpu variables require a unique name although static in some 27 * configurations (e.g. CONFIG_DEBUG_FORCE_WEAK_PER_CPU or alpha modules). 28 */ 29 #define DA_MON_NAME CONCATENATE(da_mon_, MONITOR_NAME) 30 31 static struct rv_monitor rv_this; 32 33 /* 34 * Hook to allow the implementation of hybrid automata: define it with a 35 * function that takes curr_state, event and next_state and returns true if the 36 * environment constraints (e.g. timing) are satisfied, false otherwise. 37 */ 38 #ifndef da_monitor_event_hook 39 #define da_monitor_event_hook(...) true 40 #endif 41 42 /* 43 * Hook to allow the implementation of hybrid automata: define it with a 44 * function that takes the da_monitor and performs further initialisation 45 * (e.g. reset set up timers). 46 */ 47 #ifndef da_monitor_init_hook 48 #define da_monitor_init_hook(da_mon) 49 #endif 50 51 /* 52 * Hook to allow the implementation of hybrid automata: define it with a 53 * function that takes the da_monitor and performs further reset (e.g. reset 54 * all clocks). 55 */ 56 #ifndef da_monitor_reset_hook 57 #define da_monitor_reset_hook(da_mon) 58 #endif 59 60 /* 61 * Type for the target id, default to int but can be overridden. 62 * A long type can work as hash table key (PER_OBJ) but will be downgraded to 63 * int in the event tracepoint. 64 * Unused for implicit monitors. 65 */ 66 #ifndef da_id_type 67 #define da_id_type int 68 #endif 69 70 static void react(enum states curr_state, enum events event) 71 { 72 rv_react(&rv_this, 73 "rv: monitor %s does not allow event %s on state %s\n", 74 __stringify(MONITOR_NAME), 75 model_get_event_name(event), 76 model_get_state_name(curr_state)); 77 } 78 79 /* 80 * da_monitor_reset_state - reset a monitor and setting it to init state 81 */ 82 static inline void da_monitor_reset_state(struct da_monitor *da_mon) 83 { 84 WRITE_ONCE(da_mon->monitoring, 0); 85 da_mon->curr_state = model_get_initial_state(); 86 } 87 88 /* 89 * da_monitor_reset - reset a monitor and setting it to init state 90 */ 91 static inline void da_monitor_reset(struct da_monitor *da_mon) 92 { 93 da_monitor_reset_hook(da_mon); 94 da_monitor_reset_state(da_mon); 95 } 96 97 /* 98 * da_monitor_start - start monitoring 99 * 100 * The monitor will ignore all events until monitoring is set to true. This 101 * function needs to be called to tell the monitor to start monitoring. 102 */ 103 static inline void da_monitor_start(struct da_monitor *da_mon) 104 { 105 da_mon->curr_state = model_get_initial_state(); 106 da_monitor_init_hook(da_mon); 107 /* Pairs with smp_load_acquire in da_monitoring(). */ 108 smp_store_release(&da_mon->monitoring, 1); 109 } 110 111 /* 112 * da_monitoring - returns true if the monitor is processing events 113 */ 114 static inline bool da_monitoring(struct da_monitor *da_mon) 115 { 116 /* Pairs with smp_store_release in da_monitor_start(). */ 117 return smp_load_acquire(&da_mon->monitoring); 118 } 119 120 /* 121 * da_monitor_enabled - checks if the monitor is enabled 122 */ 123 static inline bool da_monitor_enabled(void) 124 { 125 /* global switch */ 126 if (unlikely(!rv_monitoring_on())) 127 return 0; 128 129 /* monitor enabled */ 130 if (unlikely(!rv_this.enabled)) 131 return 0; 132 133 return 1; 134 } 135 136 /* 137 * da_monitor_handling_event - checks if the monitor is ready to handle events 138 */ 139 static inline bool da_monitor_handling_event(struct da_monitor *da_mon) 140 { 141 if (!da_monitor_enabled()) 142 return 0; 143 144 /* monitor is actually monitoring */ 145 if (unlikely(!da_monitoring(da_mon))) 146 return 0; 147 148 return 1; 149 } 150 151 #if RV_MON_TYPE == RV_MON_GLOBAL 152 /* 153 * Functions to define, init and get a global monitor. 154 */ 155 156 /* 157 * global monitor (a single variable) 158 */ 159 static struct da_monitor DA_MON_NAME; 160 161 /* 162 * da_get_monitor - return the global monitor address 163 */ 164 static struct da_monitor *da_get_monitor(void) 165 { 166 return &DA_MON_NAME; 167 } 168 169 /* 170 * __da_monitor_reset_all - reset the single monitor 171 */ 172 static void __da_monitor_reset_all(void (*reset)(struct da_monitor *)) 173 { 174 reset(da_get_monitor()); 175 } 176 177 /* 178 * da_monitor_reset_all - reset the single monitor 179 */ 180 static void da_monitor_reset_all(void) 181 { 182 __da_monitor_reset_all(da_monitor_reset); 183 } 184 185 /* 186 * da_monitor_reset_state_all - reset the single monitor 187 */ 188 static inline void da_monitor_reset_state_all(void) 189 { 190 __da_monitor_reset_all(da_monitor_reset_state); 191 } 192 193 /* 194 * da_monitor_init - initialize a monitor 195 */ 196 static inline int da_monitor_init(void) 197 { 198 da_monitor_reset_state_all(); 199 return 0; 200 } 201 202 /* 203 * da_monitor_destroy - destroy the monitor 204 */ 205 static inline void da_monitor_destroy(void) 206 { 207 da_monitor_reset_all(); 208 } 209 210 #elif RV_MON_TYPE == RV_MON_PER_CPU 211 /* 212 * Functions to define, init and get a per-cpu monitor. 213 */ 214 215 /* 216 * per-cpu monitor variables 217 */ 218 static DEFINE_PER_CPU(struct da_monitor, DA_MON_NAME); 219 220 /* 221 * da_get_monitor - return current CPU monitor address 222 */ 223 static struct da_monitor *da_get_monitor(void) 224 { 225 return this_cpu_ptr(&DA_MON_NAME); 226 } 227 228 /* 229 * __da_monitor_reset_all - reset all CPUs' monitor 230 */ 231 static void __da_monitor_reset_all(void (*reset)(struct da_monitor *)) 232 { 233 struct da_monitor *da_mon; 234 int cpu; 235 236 for_each_cpu(cpu, cpu_online_mask) { 237 da_mon = per_cpu_ptr(&DA_MON_NAME, cpu); 238 reset(da_mon); 239 } 240 } 241 242 /* 243 * da_monitor_reset_all - reset all CPUs' monitor 244 */ 245 static void da_monitor_reset_all(void) 246 { 247 __da_monitor_reset_all(da_monitor_reset); 248 } 249 250 /* 251 * da_monitor_reset_state_all - reset all CPUs' monitor 252 */ 253 static inline void da_monitor_reset_state_all(void) 254 { 255 __da_monitor_reset_all(da_monitor_reset_state); 256 } 257 258 /* 259 * da_monitor_init - initialize all CPUs' monitor 260 */ 261 static inline int da_monitor_init(void) 262 { 263 da_monitor_reset_state_all(); 264 return 0; 265 } 266 267 /* 268 * da_monitor_destroy - destroy the monitor 269 */ 270 static inline void da_monitor_destroy(void) 271 { 272 da_monitor_reset_all(); 273 } 274 275 #elif RV_MON_TYPE == RV_MON_PER_TASK 276 /* 277 * Functions to define, init and get a per-task monitor. 278 */ 279 280 /* 281 * The per-task monitor is stored a vector in the task struct. This variable 282 * stores the position on the vector reserved for this monitor. 283 */ 284 static int task_mon_slot = RV_PER_TASK_MONITOR_INIT; 285 286 /* 287 * da_get_monitor - return the monitor in the allocated slot for tsk 288 */ 289 static inline struct da_monitor *da_get_monitor(struct task_struct *tsk) 290 { 291 return &tsk->rv[task_mon_slot].da_mon; 292 } 293 294 /* 295 * da_get_target - return the task associated to the monitor 296 */ 297 static inline struct task_struct *da_get_target(struct da_monitor *da_mon) 298 { 299 return container_of(da_mon, struct task_struct, rv[task_mon_slot].da_mon); 300 } 301 302 /* 303 * da_get_id - return the id associated to the monitor 304 * 305 * For per-task monitors, the id is the task's PID. 306 */ 307 static inline da_id_type da_get_id(struct da_monitor *da_mon) 308 { 309 return da_get_target(da_mon)->pid; 310 } 311 312 static void __da_monitor_reset_all(void (*reset)(struct da_monitor *)) 313 { 314 struct task_struct *g, *p; 315 int cpu; 316 317 read_lock(&tasklist_lock); 318 for_each_process_thread(g, p) 319 reset(da_get_monitor(p)); 320 for_each_present_cpu(cpu) 321 reset(da_get_monitor(idle_task(cpu))); 322 read_unlock(&tasklist_lock); 323 } 324 325 static void da_monitor_reset_all(void) 326 { 327 __da_monitor_reset_all(da_monitor_reset); 328 } 329 330 static inline void da_monitor_reset_state_all(void) 331 { 332 __da_monitor_reset_all(da_monitor_reset_state); 333 } 334 335 /* 336 * da_monitor_init - initialize the per-task monitor 337 * 338 * Try to allocate a slot in the task's vector of monitors. If there 339 * is an available slot, use it and reset all task's monitor. 340 */ 341 static int da_monitor_init(void) 342 { 343 int slot; 344 345 slot = rv_get_task_monitor_slot(); 346 if (slot < 0 || slot >= RV_PER_TASK_MONITOR_INIT) 347 return slot; 348 349 task_mon_slot = slot; 350 351 da_monitor_reset_state_all(); 352 return 0; 353 } 354 355 /* 356 * da_monitor_destroy - return the allocated slot 357 * 358 * Wait for all in-flight handlers before returning the slot to avoid 359 * out-of-bound accesses. 360 */ 361 static inline void da_monitor_destroy(void) 362 { 363 if (task_mon_slot == RV_PER_TASK_MONITOR_INIT) { 364 WARN_ONCE(1, "Disabling a disabled monitor: " __stringify(MONITOR_NAME)); 365 return; 366 } 367 368 tracepoint_synchronize_unregister(); 369 da_monitor_reset_all(); 370 371 rv_put_task_monitor_slot(task_mon_slot); 372 task_mon_slot = RV_PER_TASK_MONITOR_INIT; 373 } 374 375 #elif RV_MON_TYPE == RV_MON_PER_OBJ 376 /* 377 * Functions to define, init and get a per-object monitor. 378 */ 379 380 struct da_monitor_storage { 381 da_id_type id; 382 monitor_target target; 383 union rv_task_monitor rv; 384 struct hlist_node node; 385 struct rcu_head rcu; 386 }; 387 388 #ifndef DA_MONITOR_HT_BITS 389 #define DA_MONITOR_HT_BITS 10 390 #endif 391 static DEFINE_HASHTABLE(da_monitor_ht, DA_MONITOR_HT_BITS); 392 393 /* 394 * da_create_empty_storage - pre-allocate an empty storage 395 */ 396 static inline struct da_monitor_storage *da_create_empty_storage(da_id_type id) 397 { 398 struct da_monitor_storage *mon_storage; 399 400 mon_storage = kmalloc_nolock(sizeof(struct da_monitor_storage), 401 __GFP_ZERO, NUMA_NO_NODE); 402 if (!mon_storage) 403 return NULL; 404 405 hash_add_rcu(da_monitor_ht, &mon_storage->node, id); 406 mon_storage->id = id; 407 return mon_storage; 408 } 409 410 /* 411 * da_create_storage - create the per-object storage 412 * 413 * The caller is responsible to synchronise writers, either with locks or 414 * implicitly. For instance, if da_create_storage is only called from a single 415 * event for target (e.g. sched_switch), it's safe to call this without locks. 416 */ 417 static inline struct da_monitor *da_create_storage(da_id_type id, 418 monitor_target target, 419 struct da_monitor *da_mon) 420 { 421 struct da_monitor_storage *mon_storage; 422 423 if (da_mon) 424 return da_mon; 425 426 mon_storage = da_create_empty_storage(id); 427 if (!mon_storage) 428 return NULL; 429 430 mon_storage->target = target; 431 return &mon_storage->rv.da_mon; 432 } 433 434 /* 435 * __da_get_mon_storage - get the monitor storage from the hash table 436 */ 437 static inline struct da_monitor_storage *__da_get_mon_storage(da_id_type id) 438 { 439 struct da_monitor_storage *mon_storage; 440 441 lockdep_assert_in_rcu_read_lock(); 442 hash_for_each_possible_rcu(da_monitor_ht, mon_storage, node, id) { 443 if (mon_storage->id == id) 444 return mon_storage; 445 } 446 447 return NULL; 448 } 449 450 /* 451 * da_get_monitor - return the monitor for target 452 */ 453 static struct da_monitor *da_get_monitor(da_id_type id, monitor_target target) 454 { 455 struct da_monitor_storage *mon_storage; 456 457 mon_storage = __da_get_mon_storage(id); 458 return mon_storage ? &mon_storage->rv.da_mon : NULL; 459 } 460 461 /* 462 * da_get_target - return the object associated to the monitor 463 */ 464 static inline monitor_target da_get_target(struct da_monitor *da_mon) 465 { 466 return container_of(da_mon, struct da_monitor_storage, rv.da_mon)->target; 467 } 468 469 /* 470 * da_get_id - return the id associated to the monitor 471 */ 472 static inline da_id_type da_get_id(struct da_monitor *da_mon) 473 { 474 return container_of(da_mon, struct da_monitor_storage, rv.da_mon)->id; 475 } 476 477 /* 478 * da_create_or_get - create the per-object storage if not already there 479 * 480 * This needs a lookup so should be guarded by RCU, the condition is checked 481 * directly in da_create_storage() 482 */ 483 static inline void da_create_or_get(da_id_type id, monitor_target target) 484 { 485 guard(rcu)(); 486 da_create_storage(id, target, da_get_monitor(id, target)); 487 } 488 489 /* 490 * da_fill_empty_storage - store the target in a pre-allocated storage 491 * 492 * Can be used as a substitute of da_create_storage when starting a monitor in 493 * an environment where allocation is unsafe. 494 */ 495 static inline struct da_monitor *da_fill_empty_storage(da_id_type id, 496 monitor_target target, 497 struct da_monitor *da_mon) 498 { 499 if (unlikely(da_mon && !da_get_target(da_mon))) 500 container_of(da_mon, struct da_monitor_storage, rv.da_mon)->target = target; 501 return da_mon; 502 } 503 504 /* 505 * da_get_target_by_id - return the object associated to the id 506 */ 507 static inline monitor_target da_get_target_by_id(da_id_type id) 508 { 509 struct da_monitor_storage *mon_storage; 510 511 guard(rcu)(); 512 mon_storage = __da_get_mon_storage(id); 513 514 if (unlikely(!mon_storage)) 515 return NULL; 516 return mon_storage->target; 517 } 518 519 /* 520 * da_destroy_storage - destroy the per-object storage 521 * 522 * The caller is responsible to synchronise writers, either with locks or 523 * implicitly. For instance, if da_destroy_storage is called at sched_exit and 524 * da_create_storage can never occur after that, it's safe to call this without 525 * locks. 526 * This function includes an RCU read-side critical section to synchronise 527 * against da_monitor_destroy(). 528 */ 529 static inline void da_destroy_storage(da_id_type id) 530 { 531 struct da_monitor_storage *mon_storage; 532 533 guard(rcu)(); 534 mon_storage = __da_get_mon_storage(id); 535 536 if (!mon_storage) 537 return; 538 da_monitor_reset_hook(&mon_storage->rv.da_mon); 539 hash_del_rcu(&mon_storage->node); 540 kfree_rcu(mon_storage, rcu); 541 } 542 543 static void __da_monitor_reset_all(void (*reset)(struct da_monitor *)) 544 { 545 struct da_monitor_storage *mon_storage; 546 int bkt; 547 548 guard(rcu)(); 549 hash_for_each_rcu(da_monitor_ht, bkt, mon_storage, node) 550 reset(&mon_storage->rv.da_mon); 551 } 552 553 static void da_monitor_reset_all(void) 554 { 555 __da_monitor_reset_all(da_monitor_reset); 556 } 557 558 static inline void da_monitor_reset_state_all(void) 559 { 560 __da_monitor_reset_all(da_monitor_reset_state); 561 } 562 563 static inline int da_monitor_init(void) 564 { 565 hash_init(da_monitor_ht); 566 return 0; 567 } 568 569 static inline void da_monitor_destroy(void) 570 { 571 struct da_monitor_storage *mon_storage; 572 struct hlist_node *tmp; 573 int bkt; 574 575 tracepoint_synchronize_unregister(); 576 /* 577 * This function is called after all probes are disabled and no longer 578 * pending, we can safely assume no concurrent user. 579 */ 580 synchronize_rcu(); 581 hash_for_each_safe(da_monitor_ht, bkt, tmp, mon_storage, node) { 582 da_monitor_reset_hook(&mon_storage->rv.da_mon); 583 hash_del_rcu(&mon_storage->node); 584 kfree(mon_storage); 585 } 586 } 587 588 /* 589 * Allow the per-object monitors to run allocation manually, necessary if the 590 * start condition is in a context problematic for allocation (e.g. scheduling). 591 * In such case, if the storage was pre-allocated without a target, set it now. 592 */ 593 #ifdef DA_SKIP_AUTO_ALLOC 594 #define da_prepare_storage da_fill_empty_storage 595 #else 596 #define da_prepare_storage da_create_storage 597 #endif /* DA_SKIP_AUTO_ALLOC */ 598 599 #endif /* RV_MON_TYPE */ 600 601 #if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU 602 /* 603 * Trace events for implicit monitors. Implicit monitor is the one which the 604 * handler does not need to specify which da_monitor to manipulate. Examples 605 * of implicit monitor are the per_cpu or the global ones. 606 */ 607 608 static inline void da_trace_event(struct da_monitor *da_mon, 609 char *curr_state, char *event, 610 char *next_state, bool is_final, 611 da_id_type id) 612 { 613 CONCATENATE(trace_event_, MONITOR_NAME)(curr_state, event, next_state, 614 is_final); 615 } 616 617 static inline void da_trace_error(struct da_monitor *da_mon, 618 char *curr_state, char *event, 619 da_id_type id) 620 { 621 CONCATENATE(trace_error_, MONITOR_NAME)(curr_state, event); 622 } 623 624 /* 625 * da_get_id - unused for implicit monitors 626 */ 627 static inline da_id_type da_get_id(struct da_monitor *da_mon) 628 { 629 return 0; 630 } 631 632 #elif RV_MON_TYPE == RV_MON_PER_TASK || RV_MON_TYPE == RV_MON_PER_OBJ 633 /* 634 * Trace events for per_task/per_object monitors, report the target id. 635 */ 636 637 static inline void da_trace_event(struct da_monitor *da_mon, 638 char *curr_state, char *event, 639 char *next_state, bool is_final, 640 da_id_type id) 641 { 642 CONCATENATE(trace_event_, MONITOR_NAME)(id, curr_state, event, 643 next_state, is_final); 644 } 645 646 static inline void da_trace_error(struct da_monitor *da_mon, 647 char *curr_state, char *event, 648 da_id_type id) 649 { 650 CONCATENATE(trace_error_, MONITOR_NAME)(id, curr_state, event); 651 } 652 #endif /* RV_MON_TYPE */ 653 654 /* 655 * da_event - handle an event for the da_mon 656 * 657 * This function is valid for both implicit and id monitors. 658 * Retry in case there is a race between getting and setting the next state, 659 * warn and reset the monitor if it runs out of retries. The monitor should be 660 * able to handle various orders. 661 */ 662 static inline bool da_event(struct da_monitor *da_mon, enum events event, da_id_type id) 663 { 664 enum states curr_state, next_state; 665 666 curr_state = READ_ONCE(da_mon->curr_state); 667 for (int i = 0; i < MAX_DA_RETRY_RACING_EVENTS; i++) { 668 next_state = model_get_next_state(curr_state, event); 669 if (next_state == INVALID_STATE) { 670 react(curr_state, event); 671 da_trace_error(da_mon, model_get_state_name(curr_state), 672 model_get_event_name(event), id); 673 return false; 674 } 675 if (likely(try_cmpxchg(&da_mon->curr_state, &curr_state, next_state))) { 676 if (!da_monitor_event_hook(da_mon, curr_state, event, next_state, id)) 677 return false; 678 da_trace_event(da_mon, model_get_state_name(curr_state), 679 model_get_event_name(event), 680 model_get_state_name(next_state), 681 model_is_final_state(next_state), id); 682 return true; 683 } 684 } 685 686 trace_rv_retries_error(__stringify(MONITOR_NAME), model_get_event_name(event)); 687 pr_warn("rv: " __stringify(MAX_DA_RETRY_RACING_EVENTS) 688 " retries reached for event %s, resetting monitor %s", 689 model_get_event_name(event), __stringify(MONITOR_NAME)); 690 return false; 691 } 692 693 static inline void __da_handle_event_common(struct da_monitor *da_mon, 694 enum events event, da_id_type id) 695 { 696 if (!da_event(da_mon, event, id)) 697 da_monitor_reset(da_mon); 698 } 699 700 static inline void __da_handle_event(struct da_monitor *da_mon, 701 enum events event, da_id_type id) 702 { 703 if (da_monitor_handling_event(da_mon)) 704 __da_handle_event_common(da_mon, event, id); 705 } 706 707 static inline bool __da_handle_start_event(struct da_monitor *da_mon, 708 enum events event, da_id_type id) 709 { 710 if (!da_monitor_enabled()) 711 return 0; 712 if (unlikely(!da_monitoring(da_mon))) { 713 da_monitor_start(da_mon); 714 return 0; 715 } 716 717 __da_handle_event_common(da_mon, event, id); 718 719 return 1; 720 } 721 722 static inline bool __da_handle_start_run_event(struct da_monitor *da_mon, 723 enum events event, da_id_type id) 724 { 725 if (!da_monitor_enabled()) 726 return 0; 727 if (unlikely(!da_monitoring(da_mon))) 728 da_monitor_start(da_mon); 729 730 __da_handle_event_common(da_mon, event, id); 731 732 return 1; 733 } 734 735 #if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU 736 /* 737 * Handle event for implicit monitor: da_get_monitor() will figure out 738 * the monitor. 739 */ 740 741 /* 742 * da_handle_event - handle an event 743 */ 744 static inline void da_handle_event(enum events event) 745 { 746 __da_handle_event(da_get_monitor(), event, 0); 747 } 748 749 /* 750 * da_handle_start_event - start monitoring or handle event 751 * 752 * This function is used to notify the monitor that the system is returning 753 * to the initial state, so the monitor can start monitoring in the next event. 754 * Thus: 755 * 756 * If the monitor already started, handle the event. 757 * If the monitor did not start yet, start the monitor but skip the event. 758 */ 759 static inline bool da_handle_start_event(enum events event) 760 { 761 return __da_handle_start_event(da_get_monitor(), event, 0); 762 } 763 764 /* 765 * da_handle_start_run_event - start monitoring and handle event 766 * 767 * This function is used to notify the monitor that the system is in the 768 * initial state, so the monitor can start monitoring and handling event. 769 */ 770 static inline bool da_handle_start_run_event(enum events event) 771 { 772 return __da_handle_start_run_event(da_get_monitor(), event, 0); 773 } 774 775 #elif RV_MON_TYPE == RV_MON_PER_TASK 776 /* 777 * Handle event for per task. 778 */ 779 780 /* 781 * da_handle_event - handle an event 782 */ 783 static inline void da_handle_event(struct task_struct *tsk, enum events event) 784 { 785 __da_handle_event(da_get_monitor(tsk), event, tsk->pid); 786 } 787 788 /* 789 * da_handle_start_event - start monitoring or handle event 790 * 791 * This function is used to notify the monitor that the system is returning 792 * to the initial state, so the monitor can start monitoring in the next event. 793 * Thus: 794 * 795 * If the monitor already started, handle the event. 796 * If the monitor did not start yet, start the monitor but skip the event. 797 */ 798 static inline bool da_handle_start_event(struct task_struct *tsk, 799 enum events event) 800 { 801 return __da_handle_start_event(da_get_monitor(tsk), event, tsk->pid); 802 } 803 804 /* 805 * da_handle_start_run_event - start monitoring and handle event 806 * 807 * This function is used to notify the monitor that the system is in the 808 * initial state, so the monitor can start monitoring and handling event. 809 */ 810 static inline bool da_handle_start_run_event(struct task_struct *tsk, 811 enum events event) 812 { 813 return __da_handle_start_run_event(da_get_monitor(tsk), event, tsk->pid); 814 } 815 816 #elif RV_MON_TYPE == RV_MON_PER_OBJ 817 /* 818 * Handle event for per object. 819 */ 820 821 /* 822 * da_handle_event - handle an event 823 */ 824 static inline void da_handle_event(da_id_type id, monitor_target target, enum events event) 825 { 826 struct da_monitor *da_mon; 827 828 guard(rcu)(); 829 da_mon = da_get_monitor(id, target); 830 if (likely(da_mon)) 831 __da_handle_event(da_mon, event, id); 832 } 833 834 /* 835 * da_handle_start_event - start monitoring or handle event 836 * 837 * This function is used to notify the monitor that the system is returning 838 * to the initial state, so the monitor can start monitoring in the next event. 839 * Thus: 840 * 841 * If the monitor already started, handle the event. 842 * If the monitor did not start yet, start the monitor but skip the event. 843 */ 844 static inline bool da_handle_start_event(da_id_type id, monitor_target target, 845 enum events event) 846 { 847 struct da_monitor *da_mon; 848 849 guard(rcu)(); 850 da_mon = da_get_monitor(id, target); 851 da_mon = da_prepare_storage(id, target, da_mon); 852 if (unlikely(!da_mon)) 853 return 0; 854 return __da_handle_start_event(da_mon, event, id); 855 } 856 857 /* 858 * da_handle_start_run_event - start monitoring and handle event 859 * 860 * This function is used to notify the monitor that the system is in the 861 * initial state, so the monitor can start monitoring and handling event. 862 */ 863 static inline bool da_handle_start_run_event(da_id_type id, monitor_target target, 864 enum events event) 865 { 866 struct da_monitor *da_mon; 867 868 guard(rcu)(); 869 da_mon = da_get_monitor(id, target); 870 da_mon = da_prepare_storage(id, target, da_mon); 871 if (unlikely(!da_mon)) 872 return 0; 873 return __da_handle_start_run_event(da_mon, event, id); 874 } 875 876 static inline void da_reset(da_id_type id, monitor_target target) 877 { 878 struct da_monitor *da_mon; 879 880 guard(rcu)(); 881 da_mon = da_get_monitor(id, target); 882 if (likely(da_mon)) 883 da_monitor_reset(da_mon); 884 } 885 #endif /* RV_MON_TYPE */ 886 887 #endif 888