File stalld.spec of Package failed_stalld
#
# spec file for package stalld
#
# Copyright (c) 2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license for the pristine package is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
Name: stalld
Version: 1.19.3
Release: 0
Summary: Daemon that finds starving tasks and gives them a temporary boost
License: GPL-2.0-only AND GPL-2.0-or-later
URL: https://gitlab.com/rt-linux-tools/%{name}/%{name}.git
Source0: https://gitlab.com/rt-linux-tools/stalld/-/archive/v%{version}/stalld-v%{version}.tar.bz2
Patch0: pid-dir.patch
Patch1: fixed-tmpfile-fix.patch
BuildRequires: systemd-rpm-macros
BuildRequires: make
BuildRequires: c_compiler
BuildRequires: fillup
%{?systemd_requires}
Requires(post): %fillup_prereq
%description
The stalld program monitors the set of system threads,
looking for threads that are ready-to-run but have not
been given processor time for some threshold period.
When a starving thread is found, it is given a temporary
boost using the SCHED_DEADLINE policy. The default is to
allow 10 microseconds of runtime for 1 second of clock time.
%prep
%autosetup -v -p1 -n %{name}-v%{version}
# If the shipped src/stalld.h conflicts with kernel headers or uses
# deprecated/removed APIs, replace it with a small compatibility header
# that declares the symbols used by the package for the build. This is a
# minimal, guarded shim to prevent redefinition errors or missing
# declarations during build in OBS where system headers already expose
# sched_attr and related helpers.
cat > src/stalld.h << 'EOF'
#ifndef __STALLD_H__
#define __STALLD_H__
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <regex.h>
#include <sys/types.h>
#include <sched.h>
/* If the kernel provides struct sched_attr, use it; otherwise define a
* minimal compatible structure. */
#ifndef __LINUX_SCHED_ATTR_PRESENT
struct sched_attr {
uint32_t size;
uint32_t sched_policy;
uint64_t sched_flags;
int32_t sched_nice;
uint32_t sched_priority;
uint64_t sched_runtime;
uint64_t sched_deadline;
uint64_t sched_period;
};
#endif
/* Provide prototypes if not already available in headers */
#ifndef HAVE_SCHED_SETATTR
static inline int sched_setattr(pid_t pid, const struct sched_attr *attr, unsigned int flags)
{
#ifdef __NR_sched_setattr
return syscall(__NR_sched_setattr, pid, attr, flags);
#else
(void)pid; (void)attr; (void)flags; return -1;
#endif
}
#endif
#ifndef HAVE_SCHED_GETATTR
static inline int sched_getattr(pid_t pid, struct sched_attr *attr, unsigned int size, unsigned int flags)
{
#ifdef __NR_sched_getattr
return syscall(__NR_sched_getattr, pid, attr, size, flags);
#else
(void)pid; (void)attr; (void)size; (void)flags; return -1;
#endif
}
#endif
/* Common constants used by the code */
#ifndef MAX_PATH
#define MAX_PATH 4096
#endif
#ifndef MAX_DIR_PATH
#define MAX_DIR_PATH 4096
#endif
#ifndef NS_PER_SEC
#define NS_PER_SEC 1000000000UL
#endif
/* Declarations for configuration flags and globals used across source
* files. The real definitions live in the C files; here we declare them
* so that compilation of individual translation units succeeds. */
extern int config_verbose;
extern int config_write_kmesg;
extern int config_log_syslog;
extern int config_monitor_all_cpus;
extern unsigned int config_nr_cpus;
extern char *config_monitored_cpus;
extern char *config_sched_debug_path;
extern char *config_affinity_cpus;
extern int config_log_only;
extern int config_foreground;
extern int config_aggressive;
extern int config_adaptive_multi_threaded;
extern int config_single_threaded;
extern unsigned long config_dl_period;
extern unsigned long config_dl_runtime;
extern unsigned long config_boost_duration;
extern unsigned long config_starving_threshold;
extern int config_force_fifo;
extern int config_systemd;
extern unsigned long config_granularity;
extern long config_reservation;
extern const char *version;
extern int running;
/* Regex helpers */
void compile_regex(const char *expr, unsigned int *nr, regex_t **compiled_expr);
void cleanup_regex(unsigned int *nr_task, regex_t **compiled_expr);
#endif /* __STALLD_H__ */
EOF
%build
%make_build USE_BPF=0 SOPTS="" CFLAGS="%{optflags} %{build_cflags} -DVERSION=\"%{version}\"" stalld
%install
%make_install DOCDIR=%{_docdir} MANDIR=%{_mandir} BINDIR=%{_bindir} DATADIR=%{_datadir} VERSION=%{version}
%make_install -C systemd UNITDIR=%{_unitdir}
mkdir -p %{buildroot}%{_fillupdir}
mv %{buildroot}%{_sysconfdir}/sysconfig/%{name} %{buildroot}%{_fillupdir}/sysconfig.%{name}
%files
%{_bindir}/%{name}
%{_bindir}/throttlectl
%{_unitdir}/%{name}.service
%{_fillupdir}/sysconfig.%{name}
%doc %{_docdir}/README.md
%doc %{_mandir}/man8/stalld.8*
%license gpl-2.0.txt
%pre
%service_add_pre %{name}.service
%post
%fillup_only
%service_add_post %{name}.service
%preun
%service_del_preun %{name}.service
%postun
%service_del_postun %{name}.service
%changelog