Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions testing/sched/rwsem_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# ##############################################################################
# apps/testing/sched/rwsem_test/CMakeLists.txt
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################

if(CONFIG_TESTING_RWSEM_TEST)

nuttx_add_application(
NAME
rwsem_comprehensive_test
PRIORITY
${CONFIG_TESTING_RWSEM_TEST_PRIORITY}
STACKSIZE
${CONFIG_TESTING_RWSEM_TEST_STACKSIZE}
MODULE
${CONFIG_TESTING_RWSEM_TEST}
SRCS
rwsem_comprehensive_test.c)

endif()
29 changes: 29 additions & 0 deletions testing/sched/rwsem_test/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

config TESTING_RWSEM_TEST
tristate "Reader-Writer Semaphore Comprehensive Test"
default n
---help---
Enable reader-writer semaphore optimization test suite.
This test validates the rwsem optimization that reduces
unnecessary context switches.

Test Coverage:
- Core Correctness Tests (6 tests)
- Performance Tests (3 tests)
- Basic Functionality Tests (1 test)

if TESTING_RWSEM_TEST

config TESTING_RWSEM_TEST_PRIORITY
int "RWSem test task priority"
default 100

config TESTING_RWSEM_TEST_STACKSIZE
int "RWSem test stack size"
default 8192

endif
23 changes: 23 additions & 0 deletions testing/sched/rwsem_test/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
############################################################################
# apps/testing/sched/rwsem_test/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

ifneq ($(CONFIG_TESTING_RWSEM_TEST),)
CONFIGURED_APPS += $(APPDIR)/testing/sched/rwsem_test
endif
32 changes: 32 additions & 0 deletions testing/sched/rwsem_test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
############################################################################
# apps/testing/sched/rwsem_test/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

include $(APPDIR)/Make.defs

PRIORITY = $(CONFIG_TESTING_RWSEM_TEST_PRIORITY)
STACKSIZE = $(CONFIG_TESTING_RWSEM_TEST_STACKSIZE)
MODULE = $(CONFIG_TESTING_RWSEM_TEST)

CFLAGS += -I$(TOPDIR)/sched

PROGNAME = rwsem_comprehensive_test
MAINSRC = rwsem_comprehensive_test.c

include $(APPDIR)/Application.mk
131 changes: 131 additions & 0 deletions testing/sched/rwsem_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Reader-Writer Semaphore Test Suite

## Overview

This directory contains a comprehensive test suite for NuttX reader-writer semaphore (rwsem) optimization.

**Commit ID**: `Id3b49dda0309b098f04e8ab499c28c94fe1f77ce`

## Directory Structure

```
rwsem_test/
├── CMakeLists.txt # CMake build configuration
├── Kconfig # Configuration options
├── Make.defs # Make build system integration
├── Makefile # Make build rules
├── README.md # This file
├── rwsem_comprehensive_test.c # Test source code
├── RWSEM_TEST_COVERAGE.md # Test coverage details
├── RWSEM_TEST_SUMMARY.md # Test suite summary
└── RWSEM_TEST_USAGE.md # Usage instructions
```

## Quick Start

### 1. Configuration

```bash
make menuconfig
```

Navigate to:
```
Application Configuration
└─> Testing
└─> Sched
└─> [*] Reader-Writer Semaphore Comprehensive Test
```

### 2. Build

```bash
make clean
make
```

### 3. Run

```bash
nsh> rwsem_comprehensive_test
```

## Test Contents

This test suite contains 10 comprehensive tests:

### Core Correctness Tests (Community Required)
1. Multiple readers with no writers
2. Multiple writers (exclusive access)
3. Mixed reader-writer access patterns
4. Waiter wake-up correctness
5. Lock holder tracking
6. Context switch reduction verification

### Performance Tests
7. Recursive write lock performance
8. Converted lock performance
10. High contention multi-threaded performance

### Basic Functionality Tests
9. Basic operations

## Optimization Description

This optimization reduces unnecessary context switches by only calling `up_wait()` when the lock is actually available:

- **up_write() optimization**: Only call `up_wait()` when `writer` reaches 0
- **up_read() optimization**: Only call `up_read()` when `reader` reaches 0

## Documentation

- **RWSEM_TEST_USAGE.md** - Detailed usage instructions and troubleshooting
- **RWSEM_TEST_COVERAGE.md** - Complete test coverage matrix
- **RWSEM_TEST_SUMMARY.md** - Test suite summary and technical analysis

## Configuration Options

Configurable in `make menuconfig`:

- `CONFIG_TESTING_RWSEM_TEST` - Enable/disable rwsem test
- `CONFIG_TESTING_RWSEM_TEST_PRIORITY` - Test task priority (default 100)
- `CONFIG_TESTING_RWSEM_TEST_STACKSIZE` - Test stack size (default 8192)

## Expected Results

All tests should pass with output similar to:

```
========================================
RWSem Comprehensive Test Suite
========================================
...
========================================
ALL TESTS PASSED
========================================
```

## Performance Metrics

Tests report the following metrics:

- Execution time
- Average time per operation
- Throughput (ops/ms)

## Production Validation

This optimization has been validated in production on **Vela OS** (Xiaomi's NuttX-based embedded OS) for months, running on:

- Wearable devices
- IoT devices
- Automotive systems

## Related Links

- GitHub PR: https://github.com/apache/nuttx/pull/18210
- Commit: Id3b49dda0309b098f04e8ab499c28c94fe1f77ce

## Contact

For questions, please ask in GitHub PR #18210.
Loading
Loading