tools/testing/selftests/damon/_damon_sysfs.py
Source file repositories/reference/linux-study-clean/tools/testing/selftests/damon/_damon_sysfs.py
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/damon/_damon_sysfs.py- Extension
.py- Size
- 28655 bytes
- Lines
- 869
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
# SPDX-License-Identifier: GPL-2.0
import os
ksft_skip=4
sysfs_root = None
with open('/proc/mounts', 'r') as f:
for line in f:
dev_name, mount_point, dev_fs = line.split()[:3]
if dev_fs == 'sysfs':
sysfs_root = '%s/kernel/mm/damon/admin' % mount_point
break
if sysfs_root is None:
print('Seems sysfs not mounted?')
exit(ksft_skip)
if not os.path.exists(sysfs_root):
print('Seems DAMON disabled?')
exit(ksft_skip)
def write_file(path, string):
"Returns error string if failed, or None otherwise"
string = '%s' % string
try:
with open(path, 'w') as f:
f.write(string)
except Exception as e:
return '%s' % e
return None
def read_file(path):
'''Returns the read content and error string. The read content is None if
the reading failed'''
try:
with open(path, 'r') as f:
return f.read(), None
except Exception as e:
return None, '%s' % e
class DamosAccessPattern:
size = None
nr_accesses = None
age = None
scheme = None
def __init__(self, size=None, nr_accesses=None, age=None):
self.size = size
self.nr_accesses = nr_accesses
self.age = age
if self.size is None:
self.size = [0, 2**64 - 1]
if self.nr_accesses is None:
self.nr_accesses = [0, 2**32 - 1]
if self.age is None:
self.age = [0, 2**32 - 1]
def sysfs_dir(self):
return os.path.join(self.scheme.sysfs_dir(), 'access_pattern')
def stage(self):
err = write_file(
os.path.join(self.sysfs_dir(), 'sz', 'min'), self.size[0])
if err is not None:
return err
err = write_file(
os.path.join(self.sysfs_dir(), 'sz', 'max'), self.size[1])
if err is not None:
return err
Annotation
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.