Add patch to fix CPU count on non-x86.

This commit is contained in:
Elliott Sales de Andrade 2019-03-22 22:30:17 -04:00
parent c1be96fa5f
commit b0e6f343e0
2 changed files with 59 additions and 2 deletions

View File

@ -0,0 +1,51 @@
From 49bb399e608ab564892a43a830ffd554ed240111 Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Mon, 18 Mar 2019 00:13:47 -0400
Subject: [PATCH] Get physical CPU count from lscpu if available.
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
R/linux.R | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/R/linux.R b/R/linux.R
index add8043..0d44689 100644
--- a/R/linux.R
+++ b/R/linux.R
@@ -140,7 +140,20 @@ psl__decode_address <- function(addr, family) {
}
}
-ps_cpu_count_physical_linux <- function() {
+psl__cpu_count_from_lscpu <- function() {
+ lines <- system("lscpu -p=core", intern = TRUE)
+ cores = list()
+
+ for (l in lines) {
+ if (!str_starts_with(l, "#")) {
+ cores[str_strip(l)] <- 1
+ }
+ }
+
+ length(cores)
+}
+
+psl__cpu_count_from_cpuinfo <- function() {
lines <- readLines("/proc/cpuinfo")
mapping = list()
current = list()
@@ -165,3 +178,11 @@ ps_cpu_count_physical_linux <- function() {
sum(as.integer(unlist(mapping)))
}
+
+ps_cpu_count_physical_linux <- function() {
+ if (Sys.which("lscpu") != "") {
+ psl__cpu_count_from_lscpu()
+ } else {
+ psl__cpu_count_from_cpuinfo()
+ }
+}
--
2.20.1

View File

@ -12,6 +12,7 @@ Summary: List, Query, Manipulate System Processes
License: BSD
URL: https://CRAN.R-project.org/package=%{packname}
Source0: https://cran.r-project.org/src/contrib/%{packname}_%{version}.tar.gz
Patch0001: 0001-Get-physical-CPU-count-from-lscpu-if-available.patch
# Here's the R view of the dependencies world:
# Depends:
@ -45,8 +46,12 @@ List, query and manipulate all system processes, on 'Windows', 'Linux' and
%prep
%setup -q -c -n %{packname}
pushd %{packname}
%patch0001 -p1
# Don't need coverage; it's not packaged either.
sed -i 's/covr, //g' %{packname}/DESCRIPTION
sed -i 's/covr, //g' DESCRIPTION
popd
%build
@ -86,8 +91,9 @@ _R_CHECK_FORCE_SUGGESTS_=0 %{_bindir}/R CMD check %{packname} --no-tests
%changelog
* Fri Feb 22 2019 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 1.3.0-1
* Fri Mar 22 2019 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 1.3.0-1
- Update to latest version
- Patch to work on non-x86 systems
* Thu Jan 31 2019 Fedora Release Engineering <releng@fedoraproject.org> - 1.1.0-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild