File 944.patch of Package rpm

From 82928e72b414d83be27dcb5debfe5209b246378c Mon Sep 17 00:00:00 2001
From: Panu Matilainen <pmatilai@redhat.com>
Date: Thu, 21 Nov 2019 10:33:29 +0200
Subject: [PATCH 1/2] Revert "Preserve processing order in file classification"

The order directive might be useful in some cases, but for our purposes
it very effectively serializes the whole classification operation.
Which means that we get the speed of serial classification with the
complexity of parallel execution, ugh. Revert, we need a better fix.

This reverts commit 3691d99c8bf8c81a3130333f9cbfaef704b8686f.
---
 build/rpmfc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/build/rpmfc.c b/build/rpmfc.c
index 53c6ecce0..77fdc72c4 100644
--- a/build/rpmfc.c
+++ b/build/rpmfc.c
@@ -1120,7 +1120,7 @@ rpmRC rpmfcClassify(rpmfc fc, ARGV_t argv, rpm_mode_t * fmode)
 	#pragma omp cancel parallel
     }
 
-    #pragma omp for ordered reduction(+:nerrors)
+    #pragma omp for reduction(+:nerrors)
     for (int ix = 0; ix < fc->nfiles; ix++) {
 	rpmsid ftypeId;
 	const char * ftype;
@@ -1164,6 +1164,7 @@ rpmRC rpmfcClassify(rpmfc fc, ARGV_t argv, rpm_mode_t * fmode)
 		/* only executable files are critical to dep extraction */
 		if (is_executable) {
 		    nerrors++;
+		    #pragma omp cancel for
 		}
 		/* unrecognized non-executables get treated as "data" */
 		ftype = "data";
@@ -1184,7 +1185,6 @@ rpmRC rpmfcClassify(rpmfc fc, ARGV_t argv, rpm_mode_t * fmode)
 	fc->fcolor[ix] = fcolor;
 
 	/* Add to file class dictionary and index array */
-	#pragma omp ordered
 	if (fcolor != RPMFC_WHITE && (fcolor & RPMFC_INCLUDE)) {
 	    ftypeId = rpmstrPoolId(fc->cdict, ftype, 1);
 	    #pragma omp atomic

From 5c591ce07e5f91fbda447642d64200813b44fbce Mon Sep 17 00:00:00 2001
From: Panu Matilainen <pmatilai@redhat.com>
Date: Thu, 21 Nov 2019 10:41:35 +0200
Subject: [PATCH 2/2] Generate file class dictionary after file classification
 for stability

Store the file type strings in the classifier, and generate the dictionary
and its ids serially after the parallel section completes to ensure
stable order. Besides making the classifying really run in parallel
again, this also moves the pool- and file-counting related constraints
out of the parallel section for theoretically better parallelization.

Fixes #934
---
 build/rpmfc.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/build/rpmfc.c b/build/rpmfc.c
index 77fdc72c4..f5f3793b9 100644
--- a/build/rpmfc.c
+++ b/build/rpmfc.c
@@ -67,6 +67,7 @@ struct rpmfc_s {
     rpmfcAttr *atypes;	/*!< known file attribute types */
 
     char ** fn;		/*!< (no. files) file names */
+    char ** ftype;	/*!< (no. files) file types */
     ARGV_t *fattrs;	/*!< (no. files) file attribute tokens */
     rpm_color_t *fcolor;/*!< (no. files) file colors */
     rpmsid *fcdictx;	/*!< (no. files) file class dictionary indices */
@@ -773,9 +774,11 @@ rpmfc rpmfcFree(rpmfc fc)
 	free(fc->buildRoot);
 	for (int i = 0; i < fc->nfiles; i++) {
 	    free(fc->fn[i]);
+	    free(fc->ftype[i]);
 	    argvFree(fc->fattrs[i]);
 	}
 	free(fc->fn);
+	free(fc->ftype);
 	free(fc->fattrs);
 	free(fc->fcolor);
 	free(fc->fcdictx);
@@ -1092,6 +1095,7 @@ rpmRC rpmfcClassify(rpmfc fc, ARGV_t argv, rpm_mode_t * fmode)
 
     fc->nfiles = argvCount(argv);
     fc->fn = xcalloc(fc->nfiles, sizeof(*fc->fn));
+    fc->ftype = xcalloc(fc->nfiles, sizeof(*fc->ftype));
     fc->fattrs = xcalloc(fc->nfiles, sizeof(*fc->fattrs));
     fc->fcolor = xcalloc(fc->nfiles, sizeof(*fc->fcolor));
     fc->fcdictx = xcalloc(fc->nfiles, sizeof(*fc->fcdictx));
@@ -1122,7 +1126,6 @@ rpmRC rpmfcClassify(rpmfc fc, ARGV_t argv, rpm_mode_t * fmode)
 
     #pragma omp for reduction(+:nerrors)
     for (int ix = 0; ix < fc->nfiles; ix++) {
-	rpmsid ftypeId;
 	const char * ftype;
 	const char * s = argv[ix];
 	size_t slen = strlen(s);
@@ -1164,7 +1167,6 @@ rpmRC rpmfcClassify(rpmfc fc, ARGV_t argv, rpm_mode_t * fmode)
 		/* only executable files are critical to dep extraction */
 		if (is_executable) {
 		    nerrors++;
-		    #pragma omp cancel for
 		}
 		/* unrecognized non-executables get treated as "data" */
 		ftype = "data";
@@ -1184,18 +1186,8 @@ rpmRC rpmfcClassify(rpmfc fc, ARGV_t argv, rpm_mode_t * fmode)
 
 	fc->fcolor[ix] = fcolor;
 
-	/* Add to file class dictionary and index array */
-	if (fcolor != RPMFC_WHITE && (fcolor & RPMFC_INCLUDE)) {
-	    ftypeId = rpmstrPoolId(fc->cdict, ftype, 1);
-	    #pragma omp atomic
-	    fc->fknown++;
-	} else {
-	    ftypeId = rpmstrPoolId(fc->cdict, "", 1);
-	    #pragma omp atomic
-	    fc->fwhite++;
-	}
-	/* Pool id's start from 1, for headers we want it from 0 */
-	fc->fcdictx[ix] = ftypeId - 1;
+	if (fcolor != RPMFC_WHITE && (fcolor & RPMFC_INCLUDE))
+	    fc->ftype[ix] = xstrdup(ftype);
     }
 
     if (ms != NULL)
@@ -1203,6 +1195,18 @@ rpmRC rpmfcClassify(rpmfc fc, ARGV_t argv, rpm_mode_t * fmode)
 
     } /* omp parallel */
 
+    /* Add to file class dictionary and index array */
+    for (int ix = 0; ix < fc->nfiles; ix++) {
+	const char *ftype = fc->ftype[ix] ? fc->ftype[ix] : "";
+	/* Pool id's start from 1, for headers we want it from 0 */
+	fc->fcdictx[ix] = rpmstrPoolId(fc->cdict, ftype, 1) - 1;
+
+	if (*ftype)
+	    fc->fknown++;
+	else
+	    fc->fwhite++;
+    }
+
     if (nerrors == 0)
 	rc = RPMRC_OK;