Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from netdata:master #274

Merged
merged 2 commits into from
Jan 3, 2025
Merged

Conversation

pull[bot]
Copy link

@pull pull bot commented Jan 3, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.1)

Can you help keep this open source service alive? 💖 Please sponsor : )

Summary by Sourcery

Tests:

  • Add new stress tests for various lock types, including mutex, rwlock, spinlock, rw spinlock, and waitq.

ktsaou and others added 2 commits January 3, 2025 09:46
* benchmark locks; new rw-spinlock implementation; performance improvements on waitq

* benchmark and stress r/w locks
@pull pull bot added the ⤵️ pull label Jan 3, 2025
@pull pull bot merged commit 5cbd74b into webfutureiorepo:master Jan 3, 2025
Copy link

sourcery-ai bot commented Jan 3, 2025

Reviewer's Guide by Sourcery

This pull request introduces new stress tests for locks and reimplements the reader-writer spinlock.

Sequence diagram for the updated RW spinlock read locking process

sequenceDiagram
    participant T as Thread
    participant L as RW_SPINLOCK
    T->>L: rw_spinlock_read_lock()
    activate L
    L->>L: Increment counter atomically
    Note over L: Check if WRITER_BIT is set
    alt No writer holds the lock
        L-->>T: Return success
    else Writer holds the lock
        L->>L: Decrement counter
        L->>L: Exponential backoff sleep
        L->>L: Retry
    end
    deactivate L
Loading

Sequence diagram for the updated RW spinlock write locking process

sequenceDiagram
    participant T as Thread
    participant L as RW_SPINLOCK
    T->>L: rw_spinlock_write_lock()
    activate L
    L->>L: Set WRITER_BIT atomically
    Note over L: Check previous value
    alt No readers or writers
        L->>L: Set writer thread ID
        L-->>T: Return success
    else Readers or writer present
        L->>L: Clear WRITER_BIT if readers present
        L->>L: Exponential backoff sleep
        L->>L: Retry
    end
    deactivate L
Loading

Class diagram for the updated RW_SPINLOCK implementation

classDiagram
    class RW_SPINLOCK {
        +pid_t writer
        +uint32_t counter
        +rw_spinlock_init()
        +rw_spinlock_tryread_lock()
        +rw_spinlock_read_lock()
        +rw_spinlock_read_unlock()
        +rw_spinlock_trywrite_lock()
        +rw_spinlock_write_lock()
        +rw_spinlock_write_unlock()
    }
    note for RW_SPINLOCK "Changed counter from REFCOUNT to uint32_t
Added WRITER_BIT (1U << 31) for writer lock
Added READER_MASK (~WRITER_BIT) for reader count"
Loading

Class diagram for the new benchmark structures

classDiagram
    class thread_context_t {
        +int thread_id
        +thread_type_t type
        +WAITQ_PRIORITY priority
        +lock_control_t* control
        +void* lock
        +ND_THREAD* thread
    }
    class lock_control_t {
        +uint64_t protected_counter
        +thread_stats_t stats[MAX_THREADS]
        +thread_control_t thread_controls[MAX_THREADS]
    }
    class thread_stats_t {
        +uint64_t locks
        +usec_t test_time
        +volatile int ready
    }
    class thread_control_t {
        +pthread_cond_t cond
        +pthread_mutex_t cond_mutex
        +uint64_t run_flag
    }
    thread_context_t --> lock_control_t
    lock_control_t --> thread_stats_t
    lock_control_t --> thread_control_t
Loading

File-Level Changes

Change Details Files
Added stress tests for various lock types, including mutex, reader-writer lock, spinlock, reader-writer spinlock, and wait queue.
  • Introduced new unit test options lockstest and rwlockstest to the daemon's command-line arguments.
  • Added benchmark.c, benchmark.h, benchmark-rw.c, and benchmark-rw.h to the build system.
  • Included the new benchmark header files in libnetdata.h.
src/daemon/main.c
CMakeLists.txt
src/libnetdata/libnetdata.h
src/libnetdata/locks/benchmark.c
src/libnetdata/locks/benchmark.h
src/libnetdata/locks/benchmark-rw.c
src/libnetdata/locks/benchmark-rw.h
Reimplemented the reader-writer spinlock using atomic operations and a more efficient locking mechanism.
  • Changed the internal representation of the lock counter to use a 32-bit unsigned integer.
  • Simplified the read and write lock acquisition and release logic using atomic fetch-and-or and fetch-and-and operations.
  • Introduced exponential backoff with a maximum limit for read and write lock acquisition.
  • Removed unnecessary checks and simplified the code in waitq.c.
src/libnetdata/locks/rw-spinlock.c
src/libnetdata/locks/rw-spinlock.h
src/libnetdata/locks/waitq.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants