@@ -1,220 +0,0 @@
1−From afc0c76a170bd17cbd29bbec6ae6d2227e398570 Mon Sep 17 00:00:00 2001
2−From: Alexander Couzens <lynxis@fe80.eu>
3−Date: Fri, 13 Jan 2017 22:00:37 +0100
4−Subject: [PATCH] remove frag_deflator_thread
5−
6−frag_deflator_thread compress fragments.
7−Replace the deflator_thread with a function and
8−use the function instead of the to_frag queue.
9−---
10− squashfs-tools/info.c | 5 ---
11− squashfs-tools/mksquashfs.c | 76 +++++++++++++------------------------
12− squashfs-tools/mksquashfs.h | 2 +-
13− squashfs-tools/restore.c | 15 +-------
14− 4 files changed, 30 insertions(+), 68 deletions(-)
15−
16−diff --git a/squashfs-tools/info.c b/squashfs-tools/info.c
17−index 7968c77..028d578 100644
18−--- a/squashfs-tools/info.c
19−+++ b/squashfs-tools/info.c
20−@@ -96,11 +96,6 @@ void dump_state()
21− printf("compressed block queue (deflate thread(s) -> main thread)\n");
22− dump_seq_queue(to_main, 0);
23−
24−- printf("uncompressed packed fragment queue (main thread -> fragment"
25−- " deflate thread(s))\n");
26−- dump_queue(to_frag);
27−-
28−-
29− printf("locked frag queue (compressed frags waiting while multi-block"
30− " file is written)\n");
31− dump_queue(locked_fragment);
32−diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
33−index cf48e40..cacf14c 100644
34−--- a/squashfs-tools/mksquashfs.c
35−+++ b/squashfs-tools/mksquashfs.c
36−@@ -270,10 +270,10 @@ unsigned int sid_count = 0, suid_count = 0, sguid_count = 0;
37− struct cache *reader_buffer, *fragment_buffer, *reserve_cache;
38− struct cache *bwriter_buffer, *fwriter_buffer;
39− struct queue *to_reader, *to_deflate, *to_writer, *from_writer,
40−- *to_frag, *locked_fragment, *to_process_frag;
41−+ *locked_fragment, *to_process_frag;
42− struct seq_queue *to_main;
43− pthread_t reader_thread, writer_thread, main_thread;
44−-pthread_t *deflator_thread, *frag_deflator_thread, *frag_thread;
45−+pthread_t *deflator_thread, *frag_thread;
46− pthread_t *restore_thread = NULL;
47− pthread_mutex_t fragment_mutex = PTHREAD_MUTEX_INITIALIZER;
48− pthread_mutex_t pos_mutex = PTHREAD_MUTEX_INITIALIZER;
49−@@ -323,7 +323,7 @@ struct dir_info *scan1_opendir(char *pathname, char *subpath, int depth);
50− void write_filesystem_tables(struct squashfs_super_block *sBlk, int nopad);
51− unsigned short get_checksum_mem(char *buff, int bytes);
52− void check_usable_phys_mem(int total_mem);
53−-
54−+void frag_deflator(struct file_buffer *file_buffer);
55−
56− void prep_exit()
57− {
58−@@ -1540,7 +1540,7 @@ void write_fragment(struct file_buffer *fragment)
59− pthread_mutex_lock(&fragment_mutex);
60− fragment_table[fragment->block].unused = 0;
61− fragments_outstanding ++;
62−- queue_put(to_frag, fragment);
63−+ frag_deflator(fragment);
64− pthread_cleanup_pop(1);
65− }
66−
67−@@ -2412,51 +2412,34 @@ void *deflator(void *arg)
68− }
69−
70−
71−-void *frag_deflator(void *arg)
72−+void frag_deflator(struct file_buffer *file_buffer)
73− {
74−- void *stream = NULL;
75−- int res;
76−
77−- res = compressor_init(comp, &stream, block_size, 1);
78−- if(res)
79−- BAD_ERROR("frag_deflator:: compressor_init failed\n");
80−-
81−- pthread_cleanup_push((void *) pthread_mutex_unlock, &fragment_mutex);
82−-
83−- while(1) {
84−- int c_byte, compressed_size;
85−- struct file_buffer *file_buffer = queue_get(to_frag);
86−- struct file_buffer *write_buffer =
87−+ int c_byte, compressed_size;
88−+ struct file_buffer *write_buffer =
89− cache_get(fwriter_buffer, file_buffer->block);
90−
91−- c_byte = mangle2(stream, write_buffer->data, file_buffer->data,
92−- file_buffer->size, block_size, noF, 1);
93−- compressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
94−- write_buffer->size = compressed_size;
95−- pthread_mutex_lock(&fragment_mutex);
96−- if(fragments_locked == FALSE) {
97−- fragment_table[file_buffer->block].size = c_byte;
98−- fragment_table[file_buffer->block].start_block = bytes;
99−- write_buffer->block = bytes;
100−- bytes += compressed_size;
101−- fragments_outstanding --;
102−- queue_put(to_writer, write_buffer);
103−- pthread_mutex_unlock(&fragment_mutex);
104−- TRACE("Writing fragment %lld, uncompressed size %d, "
105−- "compressed size %d\n", file_buffer->block,
106−- file_buffer->size, compressed_size);
107−- } else {
108−- add_pending_fragment(write_buffer, c_byte,
109−- file_buffer->block);
110−- pthread_mutex_unlock(&fragment_mutex);
111−- }
112−- cache_block_put(file_buffer);
113−+ c_byte = mangle2(stream, write_buffer->data, file_buffer->data,
114−+ file_buffer->size, block_size, noF, 1);
115−+ compressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
116−+ write_buffer->size = compressed_size;
117−+ if(fragments_locked == FALSE) {
118−+ fragment_table[file_buffer->block].size = c_byte;
119−+ fragment_table[file_buffer->block].start_block = bytes;
120−+ write_buffer->block = bytes;
121−+ bytes += compressed_size;
122−+ fragments_outstanding --;
123−+ queue_put(to_writer, write_buffer);
124−+ TRACE("Writing fragment %lld, uncompressed size %d, "
125−+ "compressed size %d\n", file_buffer->block,
126−+ file_buffer->size, compressed_size);
127−+ } else {
128−+ add_pending_fragment(write_buffer, c_byte,
129−+ file_buffer->block);
130− }
131−-
132−- pthread_cleanup_pop(0);
133−+ cache_block_put(file_buffer);
134− }
135−
136−-
137− struct file_buffer *get_file_buffer()
138− {
139− struct file_buffer *file_buffer = seq_queue_get(to_main);
140−@@ -4257,19 +4240,17 @@ void initialise_threads(int readq, int fragq, int bwriteq, int fwriteq,
141− multiply_overflow(processors * 3, sizeof(pthread_t)))
142− BAD_ERROR("Processors too large\n");
143−
144−- deflator_thread = malloc(processors * 3 * sizeof(pthread_t));
145−+ deflator_thread = malloc(processors * 2 * sizeof(pthread_t));
146− if(deflator_thread == NULL)
147− MEM_ERROR();
148−
149−- frag_deflator_thread = &deflator_thread[processors];
150−- frag_thread = &frag_deflator_thread[processors];
151−+ frag_thread = &deflator_thread[processors];
152−
153− to_reader = queue_init(1);
154− to_deflate = queue_init(reader_size);
155− to_process_frag = queue_init(reader_size);
156− to_writer = queue_init(bwriter_size + fwriter_size);
157− from_writer = queue_init(1);
158−- to_frag = queue_init(fragment_size);
159− locked_fragment = queue_init(fragment_size);
160− to_main = seq_queue_init();
161− reader_buffer = cache_init(block_size, reader_size, 0, 0);
162−@@ -4285,9 +4266,6 @@ void initialise_threads(int readq, int fragq, int bwriteq, int fwriteq,
163− for(i = 0; i < processors; i++) {
164− if(pthread_create(&deflator_thread[i], NULL, deflator, NULL))
165− BAD_ERROR("Failed to create thread\n");
166−- if(pthread_create(&frag_deflator_thread[i], NULL, frag_deflator,
167−- NULL) != 0)
168−- BAD_ERROR("Failed to create thread\n");
169− if(pthread_create(&frag_thread[i], NULL, frag_thrd,
170− (void *) destination_file) != 0)
171− BAD_ERROR("Failed to create thread\n");
172−diff --git a/squashfs-tools/mksquashfs.h b/squashfs-tools/mksquashfs.h
173−index 55708a3..dc5bde4 100644
174−--- a/squashfs-tools/mksquashfs.h
175−+++ b/squashfs-tools/mksquashfs.h
176−@@ -135,7 +135,7 @@ struct append_file {
177− extern struct cache *reader_buffer, *fragment_buffer, *reserve_cache;
178− struct cache *bwriter_buffer, *fwriter_buffer;
179− extern struct queue *to_reader, *to_deflate, *to_writer, *from_writer,
180−- *to_frag, *locked_fragment, *to_process_frag;
181−+ *locked_fragment, *to_process_frag;
182− extern struct append_file **file_mapping;
183− extern struct seq_queue *to_main;
184− extern pthread_mutex_t fragment_mutex, dup_mutex;
185−diff --git a/squashfs-tools/restore.c b/squashfs-tools/restore.c
186−index 5e336b3..a7aaf2e 100644
187−--- a/squashfs-tools/restore.c
188−+++ b/squashfs-tools/restore.c
189−@@ -47,8 +47,8 @@
190− #define TRUE 1
191−
192− extern pthread_t reader_thread, writer_thread, main_thread;
193−-extern pthread_t *deflator_thread, *frag_deflator_thread, *frag_thread;
194−-extern struct queue *to_deflate, *to_writer, *to_frag, *to_process_frag;
195−+extern pthread_t *deflator_thread, *frag_thread;
196−+extern struct queue *to_deflate, *to_writer, *to_process_frag;
197− extern struct seq_queue *to_main;
198− extern void restorefs();
199− extern int processors;
200−@@ -120,17 +120,6 @@ void *restore_thrd(void *arg)
201− pthread_cancel(main_thread);
202− pthread_join(main_thread, NULL);
203−
204−- /* then flush the main thread to fragment deflator thread(s)
205−- * queue. The fragment deflator thread(s) will idle
206−- */
207−- queue_flush(to_frag);
208−-
209−- /* now kill the fragment deflator thread(s) */
210−- for(i = 0; i < processors; i++)
211−- pthread_cancel(frag_deflator_thread[i]);
212−- for(i = 0; i < processors; i++)
213−- pthread_join(frag_deflator_thread[i], NULL);
214−-
215− /*
216− * then flush the main thread/fragment deflator thread(s)
217− * to writer thread queue. The writer thread will idle
218−--
219−2.17.0
220−