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

SysfsUtils: cleanup and improve interface according to the documentation #16097

Merged
merged 4 commits into from
Jan 15, 2020

Conversation

lrusak
Copy link
Contributor

@lrusak lrusak commented May 8, 2019

I'm splitting this out from #14970 as I need it for some other stuff. I have addressed the comments left on that PR here but this can probably use a fresh look over.

as written in the kernel docs:

sysfs allocates a buffer of size (PAGE_SIZE) and passes it to the
method. Sysfs will call the method exactly once for each read or
write.

When writing sysfs files, userspace processes should first read the
entire file, modify the values it wishes to change, then write the
entire buffer back.

for more info please consult the kernel documentation:

https://www.kernel.org/doc/Documentation/filesystems/sysfs.txt

@lrusak lrusak added Type: Cleanup non-breaking change which removes non-working or unmaintained functionality Type: Improvement non-breaking change which improves existing functionality Platform: Linux v19 Matrix labels May 8, 2019
@lrusak lrusak added this to the Matrix 19.0-alpha 1 milestone May 8, 2019
@lrusak lrusak requested a review from yol May 8, 2019 02:40
@lrusak lrusak mentioned this pull request May 8, 2019
6 tasks
@lrusak
Copy link
Contributor Author

lrusak commented May 11, 2019

@pkerling mind taking a look at this? I redid the interface in a more c++ manner and it seems to work in my testing. I also added a test case (which I think can be improved).

xbmc/utils/AMLUtils.cpp Outdated Show resolved Hide resolved
xbmc/utils/SysfsUtils.cpp Outdated Show resolved Hide resolved
xbmc/utils/SysfsUtils.cpp Outdated Show resolved Hide resolved
Copy link
Member

@yol yol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for the interface changes and adding tests!

Tests for the failure path would also be cool, I guess

xbmc/utils/test/TestSysfsUtils.cpp Outdated Show resolved Hide resolved
xbmc/utils/test/TestSysfsUtils.cpp Outdated Show resolved Hide resolved
@lrusak
Copy link
Contributor Author

lrusak commented May 16, 2019

anyone know what the android build error is about?

@Rechi
Copy link
Member

Rechi commented May 16, 2019

fstream can't be used on Android with an API level lower then 24 (current one is 21).

@lrusak
Copy link
Contributor Author

lrusak commented May 16, 2019

fstream can't be used on Android with an API level lower then 24 (current one is 21).

That seems weird. So the android ndk isn't c++11 compatible?

Not a big deal as we should hopefully drop amlogic support in #16043 which (I think) should remove the sysfs dependency for android

@stefansaraev
Copy link
Contributor

That seems weird. So the android ndk isn't c++11 compatible?

it has always been like that. you should bump to api24.

Not a big deal as we should hopefully drop amlogic support in #16043 which (I think) should remove the sysfs dependency for

that won't help at all. aml is linux only.

@lrusak
Copy link
Contributor Author

lrusak commented May 16, 2019

That seems weird. So the android ndk isn't c++11 compatible?

it has always been like that. you should bump to api24.

Not a big deal as we should hopefully drop amlogic support in #16043 which (I think) should remove the sysfs dependency for

that won't help at all. aml is linux only.

sysfsutils is used in amlutils which is used in the android audio sink

@jenkins4kodi jenkins4kodi added the Rebase needed PR that does not apply/merge cleanly to current base branch label Jun 6, 2019
@jenkins4kodi jenkins4kodi removed the Rebase needed PR that does not apply/merge cleanly to current base branch label Jun 6, 2019
@lrusak lrusak force-pushed the sysfs-cleanup branch 2 times, most recently from bc32d42 to b9d748a Compare July 1, 2019 16:10
xbmc/utils/SysfsUtils.cpp Outdated Show resolved Hide resolved
xbmc/utils/SysfsUtils.cpp Outdated Show resolved Hide resolved
xbmc/utils/test/TestSysfsUtils.cpp Outdated Show resolved Hide resolved
@lrusak lrusak mentioned this pull request Nov 11, 2019
7 tasks
@MilhouseVH
Copy link
Contributor

Small cosmetic issue when testing an old Atom system (kernel 5.3.y) - there's extra whitespace now present in the CPU model, that wasn't there before.

BEFORE:
s1

AFTER:
s2

/proc/cpuinfo: http://ix.io/21KC

@MilhouseVH
Copy link
Contributor

A little more info:

Old kodi.log (before these CPU/SysInfo changes): http://ix.io/21Oj

# grep Atom kodi.log
2019-11-15 08:33:05.757 T:946  NOTICE: Host CPU: Intel(R) Atom(TM) CPU D525 @ 1.80GHz, 4 cores available

New kodi.log (with these latest CPU/SysInfo changes): http://ix.io/21Ok

# grep Atom kodi.log
2019-11-15 08:36:50.422 T:936  NOTICE: Host CPU:          Intel(R) Atom(TM) CPU D525   @ 1.80GHz, 4 cores available

Copy link
Member

@yol yol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate you digging into this! Comments added.

xbmc/utils/SysfsUtils.cpp Outdated Show resolved Hide resolved
xbmc/utils/SysfsUtils.cpp Outdated Show resolved Hide resolved
xbmc/utils/SystemInfo.cpp Outdated Show resolved Hide resolved
xbmc/utils/SysfsUtils.h Outdated Show resolved Hide resolved
xbmc/utils/SysfsUtils.cpp Outdated Show resolved Hide resolved
xbmc/utils/SysfsUtils.cpp Outdated Show resolved Hide resolved
xbmc/utils/SysfsUtils.cpp Outdated Show resolved Hide resolved
xbmc/utils/SysfsUtils.h Outdated Show resolved Hide resolved
xbmc/utils/SysfsUtils.cpp Outdated Show resolved Hide resolved
@lrusak lrusak force-pushed the sysfs-cleanup branch 2 times, most recently from 0ae1ab2 to a0b7c71 Compare November 25, 2019 00:12
@MilhouseVH
Copy link
Contributor

a0b7c71 doesn't apply - it's missing

#include <regex>

that you added in b350f04

@lrusak
Copy link
Contributor Author

lrusak commented Nov 25, 2019

a0b7c71 doesn't apply - it's missing

#include <regex>

that you added in b350f04

github says it's fine to merge :/

@lrusak lrusak requested a review from yol November 25, 2019 17:22
@MilhouseVH
Copy link
Contributor

GNU patch disagrees but OK, will drop it from tonight's test builds.

xbmc/platform/linux/SysfsPath.h Outdated Show resolved Hide resolved
template<typename T>
bool Get(T& value)
{
return GetPrivate(value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the indirection?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done so I don't have to have duplicated code in the ::Set(std::string) specialization. I mirrored it for ::Get() for uniformity. I can get rid of it though for ::Get() if it's not wanted.

xbmc/platform/linux/SysfsPath.cpp Outdated Show resolved Hide resolved
}

template<>
bool CSysfsPath::Set(std::string value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this function gets called when you don't declare it in the header?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I am, The tests prove this and so does setting a breakpoint with gdb

(gdb) break CSysfsPath::Set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) 
Breakpoint 1 at 0x19cc03d: CSysfsPath::Set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >). (2 locations)
(gdb) r
Starting program: /home/lukas/Documents/git/xbmc/build/kodi-test --gtest_filter=TestSysfsPath\*

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Missing separate debuginfo for /lib64/libwayland-cursor.so.0

Note: Google Test filter = TestSysfsPath*
[==========] Running 2 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 2 tests from TestSysfsPath
[ RUN      ] TestSysfsPath.String

Breakpoint 1, CSysfsPath::Set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > (this=0x5a0a090, value='0' <repeats 200 times>...) at /home/lukas/Documents/git/xbmc/xbmc/platform/linux/SysfsPath.cpp:34
warning: Source file is more recent than executable.
34	  if (static_cast<int>(value.size()) > PAGESIZE)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try it in the release build?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function doesn't get called anywhere else then the test.

@lrusak
Copy link
Contributor Author

lrusak commented Jan 14, 2020

@yol I dropped the std::string specialisation and tests for std::string I don't think we should be writting strings (characters) to sysfs anyways (plus you need root).

Hopefully we can merge this soon 😸

@lrusak lrusak force-pushed the sysfs-cleanup branch 2 times, most recently from c5af37a to 98ee865 Compare January 14, 2020 16:14
Copy link
Member

@yol yol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh I mostly forgot what I complained about months ago so I'm just reviewing based on the current code ;-)

xbmc/platform/linux/SysfsPath.cpp Outdated Show resolved Hide resolved
xbmc/platform/linux/SysfsPath.h Outdated Show resolved Hide resolved
as written in the kernel docs:

sysfs allocates a buffer of size (PAGE_SIZE) and passes it to the
method. Sysfs will call the method exactly once for each read or
write.

for more info please consult the kernel documentation:

https://www.kernel.org/doc/Documentation/filesystems/sysfs.txt
@lrusak lrusak merged commit 3a9278b into xbmc:master Jan 15, 2020
Maven85 pushed a commit to Maven85/kodi that referenced this pull request Jan 21, 2020
SysfsUtils: cleanup and improve interface according to the documentation
@lrusak lrusak deleted the sysfs-cleanup branch February 11, 2022 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Linux Type: Cleanup non-breaking change which removes non-working or unmaintained functionality Type: Improvement non-breaking change which improves existing functionality v19 Matrix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants