% AUTHOR: Amlal El Mahrouss
% PURPOSE: WG02: Methodology for Process and Image Computation.

\documentclass[11pt, a4paper]{article}
\usepackage{graphicx}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{hyperref}
\usepackage[margin=0.5in,top=1in,bottom=1in]{geometry}

\title{Methodology for Process and Image Computation.}
\author{Amlal El Mahrouss\\amlal@nekernel.org}
\date{December 2025\\Last Edited: January 2026}

\definecolor{codegray}{gray}{0.95}
\definecolor{codeblue}{rgb}{0.1,0.1,0.8}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codepurple}{rgb}{0.58,0,0.82}

\lstset{
    language=C++,
    backgroundcolor=\color{codegray},
    basicstyle=\footnotesize\ttfamily,
    keywordstyle=\color{codeblue}\bfseries,
    commentstyle=\color{codegreen},
    stringstyle=\color{codepurple},
    numbers=left,
    numberstyle=\tiny\color{gray},
    stepnumber=1,
    numbersep=5pt,
    breaklines=true,
    breakatwhitespace=false,
    frame=single,
    rulecolor=\color{black},
    captionpos=b,
    keepspaces=true,
    showspaces=false,
    showstringspaces=false,
    showtabs=false,
    tabsize=2
}

\begin{document}

\bf \maketitle

\begin{center}
	\rule[0.01cm]{17cm}{0.01cm}
\end{center}

\abstract
{CoreProcessScheduler governs how the scheduling backend and policy of the system works, It is the common gateway for schedulers inside NeKernel based systems.}

\begin{center}
	\rule[1cm]{17cm}{0.01cm}
\end{center}

\section{I: Introduction.}

{CoreProcessScheduler (now referred as CPS) serves as the foundation between the scheduler backend and system.} {It takes care of process life-cycle management, team-based process grouping, and affinity-based CPU based allocation to mention the least.}

\subsection{II: The Affinity System.}

{Processes are given CPU time affinity hints using an affinity kind type, these hints help the scheduler run or adjust the current process.}

\subsection{Illustration: The Affinity Kind.}

{The following sample is C++ code.} {The smaller the value, the more critical the process.}

\begin{lstlisting}
enum struct AffinityKind : Int32 {
  kRealTime     = 100,
  kVeryHigh     = 150,
  kHigh         = 200,
  kStandard     = 1000,
  kLowUsage     = 1500,
  kVeryLowUsage = 2000,
};
\end{lstlisting}

\subsection{III: The Team Domain System.}

{The team system holds process metadata for the backend scheduler to run on. It holds methods and fields for backend specific operations.} {One implementation of such team is the UserProcessTeam object inside NeKernel.}

\subsection{Illustration: Team System.}

{The following sample is used to hold team metadata.} {This is part of the NeKernel source tree.}

\begin{lstlisting}
class UserProcessTeam final {
 public:
  explicit UserProcessTeam();
  ~UserProcessTeam() = default;

  NE_COPY_DEFAULT(UserProcessTeam)

  Array<UserProcess, kSchedProcessLimitPerTeam>& AsArray();
  Ref<UserProcess>&                              AsRef();
  ProcessID&                                      Id() noexcept;

 public:
  UserProcessArray mProcessList;
  UserProcessRef   mCurrentProcess;
  ProcessID          mTeamId{0};
  ProcessID          mProcessCur{0};
};
\end{lstlisting}

\subsection{IV: The Process Image System}

{The `ProcessImage' container is a system designed to contain process data, and metadata, its purpose comes from the need to separate data and code. Such usage is useful for validation and vettability.} {This approach helps separate concerns and give modularity to the system, as the image and process structure are not mixed together.}

\subsection{Illustration: Process Image System.}

{The following sample is a container used to hold process data and metadata.} {This is part of the NeKernel source tree.}

\begin{lstlisting}
using ImagePtr = VoidPtr;

struct ProcessImage final {
  explicit ProcessImage() = default;

 private:
  friend UserProcess;
  friend KernelTask;

  friend class UserProcessScheduler;

  ImagePtr fCode;
  ImagePtr fBlob;

 public:
  Bool HasCode() const { return this->fCode != nullptr; }

  Bool HasImage() const { return this->fBlob != nullptr; }

  ErrorOr<ImagePtr> LeakImage() {
    if (this->fCode) {
      return ErrorOr<ImagePtr>{this->fCode};
    }
  }

  ErrorOr<ImagePtr> LeakBlob() {
    if (this->fBlob) {
      return ErrorOr<ImagePtr>{this->fBlob};
    }
  }
};
\end{lstlisting}

\section{V: Conclusion.}

{The CPS is a system with provable domains and separation of computation, it governs how a Process Domain shall compute its child processes, it does not provide the algorithms.} {Which is why, one scheduler backend (such as the UserProcessScheduler) takes care of user process scheduling and fairness.}

\section{References}

\begin{enumerate}
    \item CoreProcessScheduler.h (2025), \href{https://github.com/ne-foss-org/nekernel/blob/develop/src/kernel/KernelKit/CoreProcessScheduler.h}{github.com}
    
    \item NeKernel.org (2025), \href{https://nekernel.org/nekernel}{nekernel.org}
    \item Scheduling: Introduction (2012), \href{https://pages.cs.wisc.edu/~remzi/OSTEP/cpu-sched.pdf}{pages.cs.wisc.edu}
    
    \item  Processor Affinity, Multiple CPU Scheduling (2003), \href{https://www.tmurgent.com/WhitePapers/ProcessorAffinity.pdf}{tmurgent.com}
    
    \item El Mahrouss, A. (2026). Methodology for Freestanding Development.\\ Zenodo. https://doi.org/10.5281/zenodo.18362425
    
    \item El Mahrouss, A. (2026). The Execution Semantics: On Axioms, Domains, and Authority. (v1.0.0). Zenodo. https://doi.org/10.5281/zenodo.18362375
\end{enumerate}

\end{document}