3 ms·
I ran into issues with M1 core scheduling recently in one of my applications: https://github.com/corrscope/corrscope/#m1-slowdown= https://github.com/corrscope/
by nyanpasu64 5y ago
I ran into issues with M1 core scheduling recently in one of my applications: https://github.com/corrscope/corrscope/#m1-slowdown= https://github.com/corrscope/corrscope/#m1-slowdown=
corrscope is a PyQt app with a background thread which streams video frames to a ffplay process, which shows these frames in a video player window along with synchronized audio. During playback, ffplay is focused and corrscope lies in the background generating video frames.
> On M1 processors, if you open preview, after 40 or so seconds, the preview may suddenly slow down and audio will stop playing. This is because macOS thinks ffplay is the active app, and Corrscope is a background job burning CPU, so it moves Corrscope to an Efficiency core, slowing it down.
> There is no fix for this issue at the moment. As a workaround, you can click on Corrscope's window to avoid the slowdown, and drag it aside so it doesn't obstruct the preview.
Setting the background worker thread to QOS_CLASS_USER_INTERACTIVE does not prevent it from being moved to E-cores. This is a rather severe issue which damages the user experience, and I haven't found a workaround yet (outside of moving video playback in-process). How do Chrome and Firefox (and Safari I suppose) give their worker processes P-cores while users are interacting with the browser window process?
- saagarjha 5y agoPerhaps you are running into App Nap?
- deleted 5y ago[deleted]
- nyanpasu64 5y agoNot sure why you're downvoted; you seem to be right! In Activity Monitor's Energy tab, I have to expand Terminal > login > zsh > python, but my python process is shown as App Nap: Yes. How would I opt a program out of App Nap? Should I trust https://pypi.org/project/appnope/ https://pypi.org/project/appnope/?
- dave78 5y agoI've used AppNope with success, though I've never tested on an M1.
- jamesfmilne 5y agoThis is how you do it from Objective-C: // Call NSProcessInfo to disable AppNap et al. NSActivityOptions activityOptions = NSActivityIdleDisplaySleepDisabled | NSActivityIdleSystemSleepDisabled | NSActivityLatencyCritical; NSProcessInfo* procInfo = [NSProcessInfo processInfo]; m_NoSleepActivity = [procInfo beginActivityWithOptions:activityOptions reason:@"Running some stuff"];
- ninkendo 5y ago> How do Chrome and Firefox (and Safari I suppose) give their worker processes P-cores while users are interacting with the browser window process? Generally if a UI process makes IPC calls out to a daemon or other process, the Mach kernel is supposed to keep track of prioritization and an on-behalf-of relationship for the daemon. That is, if the kernel already thinks the foreground app is P-core eligible, any work it initiates in other processes via IPC should be P-core eligible as well, through a “voucher” object that is passed between processes: https://opensource.apple.com/source/xnu/xnu-3789.41.3/osfmk/ipc/ipc_voucher.h.auto.html https://opensource.apple.com/source/xnu/xnu-3789.41.3/osfmk/... I’m not sure the mechanism you’re using to put video playback out-of-process, but if there’s any IPC calls involved, make sure they’re originating from a UI task, and not the other way around? Hopefully this gives you something to go on.
- nyanpasu64 5y agoFrames are passed through a Unix pipeline (to stdin rather than a named pipe). What's a UI task?
- conradev 5y agoIs the python process a direct child of the UI process?
- nyanpasu64 5y agoThe Python thread shares a process with the GUI thread. It actually pipes data to a ffmpeg process in between, to mix video frames and audio into a NUT stream, which gets piped to the ffplay GUI process. IIRC both processes are created by Python, but we only pipe data directly into ffmpeg.