[PATCH 1/6] count: Employ new scheme for snippet of count_lim_app

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>From ea84d6ff5dd7e0a0f89d8eacf844d920298584b9 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <akiyks@xxxxxxxxx>
Date: Mon, 8 Oct 2018 16:08:59 +0900
Subject: [PATCH 1/6] count: Employ new scheme for snippet of count_lim_app

Signed-off-by: Akira Yokosawa <akiyks@xxxxxxxxx>
---
 CodeSamples/count/count_lim_app.c | 11 ++++++++---
 count/count.tex                   | 40 ++++++---------------------------------
 2 files changed, 14 insertions(+), 37 deletions(-)

diff --git a/CodeSamples/count/count_lim_app.c b/CodeSamples/count/count_lim_app.c
index 0bdf6b0..1817c19 100644
--- a/CodeSamples/count/count_lim_app.c
+++ b/CodeSamples/count/count_lim_app.c
@@ -21,6 +21,7 @@
 
 #include "../api.h"
 
+//\begin{snippet}[labelbase=ln:count:count_lim_app:variable,commandchars=\\\@\$]
 unsigned long __thread counter = 0;
 unsigned long __thread countermax = 0;
 unsigned long globalcountmax = 10000;
@@ -29,6 +30,7 @@ unsigned long globalreserve = 0;
 unsigned long *counterp[NR_THREADS] = { NULL };
 DEFINE_SPINLOCK(gblcnt_mutex);
 #define MAX_COUNTERMAX 100
+//\end{snippet}
 
 static void globalize_count(void)
 {
@@ -38,18 +40,21 @@ static void globalize_count(void)
 	countermax = 0;
 }
 
+//\begin{snippet}[labelbase=ln:count:count_lim_app:balance,commandchars=\\\[\]]
 static void balance_count(void)
 {
-	countermax = globalcountmax - globalcount - globalreserve;
+	countermax = globalcountmax -
+	             globalcount - globalreserve;
 	countermax /= num_online_threads();
-	if (countermax > MAX_COUNTERMAX)
-		countermax = MAX_COUNTERMAX;
+	if (countermax > MAX_COUNTERMAX)	//\lnlbl{enforce:b}
+		countermax = MAX_COUNTERMAX;	//\lnlbl{enforce:e}
 	globalreserve += countermax;
 	counter = countermax / 2;
 	if (counter > globalcount)
 		counter = globalcount;
 	globalcount -= counter;
 }
+//\end{snippet}
 
 int add_count(unsigned long delta)
 {
diff --git a/count/count.tex b/count/count.tex
index 3598aac..90d0936 100644
--- a/count/count.tex
+++ b/count/count.tex
@@ -1759,44 +1759,13 @@ This task is undertaken in the next section.
 \label{sec:count:Approximate Limit Counter Implementation}
 
 \begin{listing}[tbp]
-{ \scriptsize
-\begin{verbbox}
-  1 unsigned long __thread counter = 0;
-  2 unsigned long __thread countermax = 0;
-  3 unsigned long globalcountmax = 10000;
-  4 unsigned long globalcount = 0;
-  5 unsigned long globalreserve = 0;
-  6 unsigned long *counterp[NR_THREADS] = { NULL };
-  7 DEFINE_SPINLOCK(gblcnt_mutex);
-  8 #define MAX_COUNTERMAX 100
-\end{verbbox}
-}
-\centering
-\theverbbox
+\input{CodeSamples/count/count_lim_app@xxxxxxxxxxxx}
 \caption{Approximate Limit Counter Variables}
 \label{lst:count:Approximate Limit Counter Variables}
 \end{listing}
 
 \begin{listing}[tbp]
-{ \scriptsize
-\begin{verbbox}
-  1 static void balance_count(void)
-  2 {
-  3   countermax = globalcountmax -
-  4                globalcount - globalreserve;
-  5   countermax /= num_online_threads();
-  6   if (countermax > MAX_COUNTERMAX)
-  7     countermax = MAX_COUNTERMAX;
-  8   globalreserve += countermax;
-  9   counter = countermax / 2;
- 10   if (counter > globalcount)
- 11     counter = globalcount;
- 12   globalcount -= counter;
- 13 }
-\end{verbbox}
-}
-\centering
-\theverbbox
+\input{CodeSamples/count/count_lim_app@xxxxxxxxxxx}
 \caption{Approximate Limit Counter Balancing}
 \label{lst:count:Approximate Limit Counter Balancing}
 \end{listing}
@@ -1813,12 +1782,15 @@ Listing~\ref{lst:count:Simple Limit Counter Variables},
 with the addition of \co{MAX_COUNTERMAX}, which sets the maximum
 permissible value of the per-thread \co{countermax} variable.
 
+\begin{lineref}[ln:count:count_lim_app:balance]
 Similarly,
 Listing~\ref{lst:count:Approximate Limit Counter Balancing}
 is identical to the \co{balance_count()} function in
 Listing~\ref{lst:count:Simple Limit Counter Utility Functions},
-with the addition of lines~6 and~7, which enforce the
+with the addition of
+lines~\lnref{enforce:b} and~\lnref{enforce:e}, which enforce the
 \co{MAX_COUNTERMAX} limit on the per-thread \co{countermax} variable.
+\end{lineref}
 
 \subsection{Approximate Limit Counter Discussion}
 
-- 
2.7.4





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux