arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2212.05468cs.LOcs.PL
收藏

McMini:一种面向多线程程序的、基于 DPOR 的可编程模型检查器

McMini: A Programmable DPOR-Based Model Checker for Multithreaded Programs

Maxwell Pirtle, Luka Jovanovic, Gene Cooperman

AI总结:

本文提出可扩展的 DPOR 模型检查器 McMini,支持用少量 C 代码定义原语线程操作与唤醒策略,从而减少调度搜索并显著提升多线程程序验证效率。

摘要:

背景:模型检查已成为增强多线程程序正确性信心的关键工具。单元测试和功能测试并不足够,因为它们无法发现竞争条件。模型检查工具可解决这一问题。一个简单的模型检查器有助于在投入生产前检测竞争条件。\n研究问题:当前的模型检查器将常见线程操作的行为硬编码,并且无法识别依赖于应用的线程范式或使用更简单原语操作实现的函数。这会引入额外操作,导致当前模型检查器过慢。此外,也没有机制对底层线程库或操作系统中实际实现的线程唤醒策略语义进行建模。消除这些限制可以使模型检查器更快。\n方法:McMini 是一个基于 DPOR(动态偏序归约)的可扩展模型检查器。本文发明了一种机制,用于向 McMini 声明新的原语线程操作,通常只需不超过约 100 行 C 代码。该机制还被扩展,使 McMini 用户可以声明替代的线程唤醒策略,包括条件变量的虚假唤醒。\n知识:在 McMini 中,用户定义新的线程操作。用户通过向 DPOR 算法声明可减少待搜索线程调度数量的信息来优化这些操作。需要声明:(i)操作在何种条件下可用;(ii)哪些线程操作彼此独立;以及(iii)何时两个操作可被视为共同可用。可选的唤醒策略通过定义等待操作(针对信号量、条件变量等)何时可用来实现。文中描述了一种新的入队线程操作,允许用户声明替代唤醒策略。\n验证:McMini 首先被确认能够作为传统但可扩展的模型检查器,针对互斥锁、信号量、条件变量和读写锁正确且高效地运行。随后,在代表其他有用多线程操作范式的新型原语操作上测试了 McMini 的可扩展性,例如 readers-and-two-writers。结果发现,与构建在条件变量之上的传统实现相比,模型检查速度快五倍甚至更多。接着使用入队操作测试了替代唤醒策略(例如 FIFO、LIFO、任意等)。最后,使用一个仅在存在虚假唤醒时才暴露缺陷的程序测试了虚假唤醒。\n重要性:许多应用使用超越传统互斥锁、信号量和条件变量的多线程范式函数,它们构建在基本操作之上。直接为这些范式定义新原语的能力,使模型检查器能够通过搜索更少的线程调度而更快运行。对特定线程唤醒策略(包括条件变量的虚假唤醒)进行建模的能力也很重要。需要注意,POSIX 未定义 `pthread_mutex_lock`、`sem_wait` 和 `pthread_cond_wait` 的唤醒策略。POSIX 线程实现随后会选择特定策略(例如 FIFO、任意),而 McMini 可以直接对其建模。

英文摘要:

Context: Model checking has become a key tool for gaining confidence in correctness of multi-threaded programs. Unit tests and functional tests do not suffice because of race conditions that are not discovered by those tests. This problem is addressed by model checking tools. A simple model checker is useful for detecting race conditions prior to production. Inquiry: Current model checkers hardwire the behavior of common thread operations, and do not recognize application-dependent thread paradigms or functions using simpler primitive operations. This introduces additional operations, causing current model checkers to be excessively slow. In addition, there is no mechanism to model the semantics of the actual thread wakeup policies implemented in the underlying thread library or operating system. Eliminating these constraints can make model checkers faster. Approach: McMini is an **extensible** model checker based on DPOR (Dynamic Partial Order Reduction). A mechanism was invented to declare to McMini new, primitive thread operations, typically in 100~lines or less of C~code. The mechanism was extended to also allow a user of McMini to declare alternative thread wakeup policies, including spurious wakeups from condition variables. Knowledge: In McMini, the user defines new thread operations. The user optimizes these operations by declaring to the DPOR algorithm information that reduces the number of thread schedules to be searched. One declares: (i) under what conditions an operation is enabled; (ii) which thread operations are independent of each other; and (iii) when two operations can be considered as co-enabled. An optional wakeup policy is implemented by defining when a wait operation (on a semaphore, condition variable, etc.) is enabled. A new enqueue thread operation is described, allowing a user to declare alternative wakeup policies. Grounding: McMini was first confirmed to operate correctly and efficiently as a traditional, but extensible model checker for mutex, semaphore, condition variable, and reader-writer lock. McMini's extensibility was then tested on novel primitive operations, representing other useful paradigms for multithreaded operations. An example is readers-and-two-writers. The speed of model checking was found to be five times faster and more, as compared to traditional implementations on top of condition variables. Alternative wakeup policies (e.g., FIFO, LIFO, arbitrary, etc.) were then tested using an enqueue operation. Finally, spurious wakeups were tested with a program that exposes a bug **only** in the presence of a spurious wakeup. Importance: Many applications employ functions for multithreaded paradigms that go beyond the traditional mutex, semaphore, and condition variables. They are defined on top of basic operations. The ability to directly define new primitives for these paradigms makes model checkers run faster by searching fewer thread schedules. The ability to model particular thread wakeup policies, including spurious wakeup for condition variables, is also important. Note that POSIX leaves undefined the wakeup policies of `pthread_mutex_lock`, `sem_wait`, and `pthread_cond_wait`. The POSIX thread implementation then chooses a particular policy (e.g., FIFO, arbitrary), which can be directly modeled by McMini.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑