-
Notifications
You must be signed in to change notification settings - Fork 5.2k
SunOS process and thread support #105403
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
base: main
Are you sure you want to change the base?
SunOS process and thread support #105403
Conversation
Lets drop the changes which are already submitted in other PRs. |
src/libraries/Common/src/Interop/SunOS/procfs/Interop.ProcFsStat.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.SunOS.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.BSD.cs
Show resolved
Hide resolved
Good start! I've left initial feedback, which I anticipate the maintainers will point out. :) |
Thanks. I had not yet seen #105207 when I opened this. I think @AustinWise and I should figure out how to get the prerequisite fixes shown there (and here) all integrated, and then I'll rebase the last parts of this onto that. |
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.SunOS.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.SunOS.cs
Outdated
Show resolved
Hide resolved
I'd love to, but I do not see a way to do "stacked" PRs, where one PR targets the branch of another PR. |
Create a local branch |
RISC-V Release-CLR-QEMU: 9082 / 9112 (99.67%)
report.xml, report.md, failures.xml, testclr_details.tar.zst RISC-V Release-CLR-VF2: 9083 / 9113 (99.67%)
report.xml, report.md, failures.xml, testclr_details.tar.zst RISC-V Release-FX-QEMU: 278604 / 279696 (99.61%)
report.xml, report.md, failures.xml, testclr_details.tar.zst RISC-V Release-FX-VF2: 309598 / 311334 (99.44%)
report.xml, report.md, failures.xml, testclr_details.tar.zst Build information and commandsGIT: |
* Fix illumos compile error at minipal/debugger.c:127 dotnet/runtime/src/native/minipal/debugger.c:127:5: error: implicit declaration of function 'snprintf' [-Werror=implicit-function-declaration] 127 | snprintf(statusFilename, sizeof(statusFilename), "/proc/%d/status", getpid()); | ^~~~~~~~ * Fix illumos compile error in minipal/thread.h src/native/minipal/thread.h:73:23: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast] 73 | tid = (size_t)(void*)pthread_self(); | ^~~~~~~~~~~~~~~~~~~~~ * Fix illumos compile error in native/libs/System.Native/pal_mount.c src/native/libs/System.Native/pal_mount.c:164:38: error: 'struct statvfs' has no member named 'f_type' 164 | *formatType = (int64_t)(stats.f_type); | ^ * Fix illumos compile error in coreclr/pal/src/thread/thread.cpp /home/gwr/dotnet/runtime/src/coreclr/pal/src/thread/thread.cpp:1367:5: error: 'cid' was not declared in this scope 1367 | cid = CLOCK_THREAD_CPUTIME_ID; | ^~~
I'm still not sure how to get the System.Diagnostics.Process/test stuff onto my test host and run it. I've tried to follow the workflow documents but those don't say much about cross builds like I have to do. Cook-book commands would be a great help. Thx! |
There is no easy way to run libraries tests when we are in the middle of porting shared framework (itself) and sdk/msbuild aren't fully functional on the platform. The improvised way involves gathering references and assemblies then feed it to dotnet(1) same as how the test command line gets serialized on linux. If you are unfamiliar with sdk/msbuild commands, it complicates things further. |
OK, so I'm trying to become more familiar, and have tried looking at how this works on linux. I'm building like this:
and then copying this over to the illumos test system and unpack:
That much gives me a working |
I think your test program from #34944 (comment) is sufficient for now. Just add process spawn case and if that works, we are good to go for this initial iteration. New platform (especially new operating system as opposed to new arch) isn't a smooth sail and engineering doesn't pay too much attention to it during larger refactoring (mainly because it's once in a lifetime thing for a given platform). Once, System.Diagnostics.Process and the remaining two libs are ported, we can get a full blown SDK though source-build. Then it'd be a matter of extracting that SDK at root of the repo cloned in illumos based OS and running |
Any more feedback? Thanks. (bump?) |
|
||
<!-- The following RIDs are not officically supported and are not | ||
built during official builds, however we wish to include them | ||
in our runtime.json to enable others to provide them. --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the runtime.json that this talks about going to show up?
I am wondering whether this is still needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the runtime.json that this talks about going to show up?
runtime/src/installer/pkg/projects/Directory.Build.props
Lines 80 to 86 in b3de022
<!-- Include Unofficial Build RIDs in runtime.json's but do not include in the platform manifest --> | |
<BuildRID Include="@(UnofficialBuildRID)" Exclude="@(_buildingOnRID)"> | |
<ExcludeFromPlatformManifest>true</ExcludeFromPlatformManifest> | |
</BuildRID> | |
<BuildRID Include="@(_buildingOnRID)"/> | |
<RestoreBuildRID Include="@(BuildRID)" Exclude="@(UnofficialBuildRID)" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does BuildRID
flow to runtime.json? What's the path to the runtime.json file? Is it shipping anywhere?
I think it would be best to separate the infra changes from the System.Diagnostics.Process changes. PRs that combine multiple completely unrelated fixes are hard to land.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, this code is here for ages. PR isn't inventing anything new.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I know it has been there for ages. I am trying to understand what it is still used for and whether it is still needed. I am not able to able to find runtime.json that the comment talks about.
src/libraries/Common/src/Interop/SunOS/procfs/Interop.ProcFs.Definitions.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/src/Interop/SunOS/procfs/Interop.ProcFs.Definitions.cs
Show resolved
Hide resolved
src/libraries/Common/src/Interop/SunOS/procfs/Interop.ProcFs.Definitions.cs
Outdated
Show resolved
Hide resolved
After the recent merge of main into the PR branch, I'm getting a build error I don't understand:
Help? (resolved below. See #119447) |
Looks related to #119112 |
Thanks. I picked up changes through Aug 30 (including that fix) but I'm still getting the error. That business with destructors is a bit tricky for me to figure out. |
This seems to let it build. Does this look right?
I went ahead and created a PR with this: #119447 |
I'm catching up with the merge first, and then updating as requested in reviews. |
Base now on main as of Aug 30. to pick up #119112 |
Read /proc (binary) psinfo for System.Diagnostic.Process using src/native/libs/System.Native C functions. Add native/libs/System.Native/pal_io.c etc. Add src/libraries/Common/src/Interop/SunOS/procfs Add src/libraries/System.Diagnostics.Process Co-authored-by: Austin Wise <AustinWise@gmail.com> Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
Pushed new version with changes requested by reviewers, Note that to build this, three other changes are requied:
In case anyone wants to build this, here's a branch with all four changes: |
internal int Tid; | ||
internal int Priority; | ||
internal int NiceVal; | ||
internal char StatusCode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is uint8_t
in the unmanaged view. It should be byte
here.
(char is 16-bit in C#, so there is a mismatch between the managed and unmanaged definitions.)
<Compile Include="$(CommonPath)Interop\SunOS\procfs\Interop.ProcFs.Definitions.cs" | ||
Link="Common\Interop\SunOS\procfs\Interop.ProcFs.Definitions.cs" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<Compile Include="$(CommonPath)Interop\SunOS\procfs\Interop.ProcFs.Definitions.cs" | |
Link="Common\Interop\SunOS\procfs\Interop.ProcFs.Definitions.cs" /> | |
<Compile Include="$(CommonPath)Interop\SunOS\procfs\Interop.ProcFs.cs" | |
Link="Common\Interop\SunOS\procfs\Interop.ProcFs.cs" /> |
Nit: There is no other *.Definitions.cs
file under libraries. To follow the repo conventions, this should be Interop.ProcFs.cs
or Interop.ProcFs.Common.cs
- if there is anything left in this file after incorporating the other feedback.
// Output type for TryGetProcessInfoById() | ||
// Keep in sync with pal_io.h ProcessInfo | ||
[StructLayout(LayoutKind.Sequential)] | ||
internal struct ProcessInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would make more sense for this to be in Interop.ProcFs.TryGetProcessInfoById.cs. We typically place the structures that support the internal API in the same file as the API, so that one can include the least amount of interop goo a lot of unnecessary goo to use the internal API.
internal char StatusCode; | ||
} | ||
|
||
internal static string GetInfoFilePathForProcess(int pid) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks unused
internal static string GetLwpDirForProcess(int pid) => | ||
$"{RootPath}{(uint)pid}{lwpDirName}"; | ||
|
||
internal static string GetInfoFilePathForThread(int pid, int tid) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks unused
} | ||
return iinfo; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interop.procfs.ProcessInfo iinfo; | ||
if (!Interop.procfs.TryGetProcessInfoById(_processId, out iinfo)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interop.procfs.ProcessInfo iinfo; | |
if (!Interop.procfs.TryGetProcessInfoById(_processId, out iinfo)) | |
Interop.procfs.ProcessInfo processInfo; | |
if (!Interop.procfs.TryGetProcessInfoById(_processId, out processInfo)) |
Does the i
prefix in iinfo
mean something?
{ | ||
public partial class Process : IDisposable | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// <param name="pid">PID of the process to read status info for.</param> | ||
/// <param name="processInfo">The pointer to ProcessInfo instance.</param> | ||
/// <returns> | ||
/// true if the process status was read; otherwise, false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method implementation throws on errors. It never returns false. Should it be void GetProcessInfoById
instead? (dtto for other similar Try methods)
ProcessInfo info = default; | ||
if (ReadProcessInfo(pid, &info, null, 0) < 0) | ||
{ | ||
Interop.ErrorInfo errorInfo = Sys.GetLastErrorInfo(); | ||
throw new IOException(errorInfo.GetErrorMessage(), errorInfo.RawErrno); | ||
} | ||
processInfo = info; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ProcessInfo info = default; | |
if (ReadProcessInfo(pid, &info, null, 0) < 0) | |
{ | |
Interop.ErrorInfo errorInfo = Sys.GetLastErrorInfo(); | |
throw new IOException(errorInfo.GetErrorMessage(), errorInfo.RawErrno); | |
} | |
processInfo = info; | |
fixed (ProcessInfo* pProcessInfo = &processInfo) | |
{ | |
if (ReadProcessInfo(pid, pProcessInfo, null, 0) < 0) | |
{ | |
Interop.ErrorInfo errorInfo = Sys.GetLastErrorInfo(); | |
throw new IOException(errorInfo.GetErrorMessage(), errorInfo.RawErrno); | |
} | |
} |
ProcessInfo is a structure with non-trivial size. It would be better to pin it to avoid unnecessary copying. (dtto for other similar places)
Read binary psinfo for System.Diagnostic.Process on SunOS (Solaris or illumos).
No failures in System.Diagnostic.Process.Tests (but lots of skip)
BTW, I tried rebasing on main from Mon. this week and ran into problems downloading stuff.
Not sure why, but it didn't seem to have anything to do with my changes.