Commit 1070f517 authored by Andrey Filippov's avatar Andrey Filippov

fixed closing file error, more debugging

parent 8eee4caa
...@@ -2049,8 +2049,9 @@ unsigned int select_port(camogm_state *state) ...@@ -2049,8 +2049,9 @@ unsigned int select_port(camogm_state *state)
} }
if ((state->prog_state == STATE_STARTING) || (state->prog_state == STATE_RUNNING)) { if ((state->prog_state == STATE_STARTING) || (state->prog_state == STATE_RUNNING)) {
// if (lseek(state->fd_circ[port], LSEEK_CIRC_READY, SEEK_END) < 0) { // if (lseek(state->fd_circ[port], LSEEK_CIRC_READY, SEEK_END) < 0) {
D3(if ((chn >=0) && (lseek(state->fd_circ[chn], LSEEK_CIRC_READY, SEEK_END) >= 0)) \ // fprintf(debug_file, "selected port: %i, min free size = %08ld @ %07d\n", chn, min_sz, get_fpga_usec(state->fd_fparmsall[0], 0));
fprintf(debug_file, "selected port: %i, min free size = %08ld @ %07d\n", chn, min_sz, get_fpga_usec(state->fd_fparmsall[0], 0)); \ D1(if ((chn >=0) && (lseek(state->fd_circ[chn], LSEEK_CIRC_READY, SEEK_END) >= 0)) \
fprintf(debug_file, "selected port: %i, min free size = %08ld ", chn, min_sz); \
else if (debug_level >= 6) fprintf(debug_file,"no port is ready @ %07d\n", get_fpga_usec(state->fd_fparmsall[0], 0))); else if (debug_level >= 6) fprintf(debug_file,"no port is ready @ %07d\n", get_fpga_usec(state->fd_fparmsall[0], 0)));
} }
......
...@@ -54,7 +54,7 @@ static inline void vectcpy(struct iovec *dest, void *src, size_t len) ...@@ -54,7 +54,7 @@ static inline void vectcpy(struct iovec *dest, void *src, size_t len)
} }
/** Set @e len bytes with @e src to buffer pointed by @e dest vector */ /** Set @e len bytes with @e src to buffer pointed by @e dest vector */
static inline void vectset(struct iovec *dest, int src, size_t len) static void vectset(struct iovec *dest, int src, size_t len)
{ {
unsigned char *d = (unsigned char *)dest->iov_base; unsigned char *d = (unsigned char *)dest->iov_base;
D6(fprintf(debug_file, "_13c06a?_:vectset() d=%p, src=%d len=%d\n", d, src, len )); D6(fprintf(debug_file, "_13c06a?_:vectset() d=%p, src=%d len=%d\n", d, src, len ));
...@@ -92,6 +92,20 @@ static inline unsigned char *vectrpos(struct iovec *vec, size_t offset) ...@@ -92,6 +92,20 @@ static inline unsigned char *vectrpos(struct iovec *vec, size_t offset)
return (unsigned char *)vec->iov_base + (vec->iov_len - offset); return (unsigned char *)vec->iov_base + (vec->iov_len - offset);
} }
/** extend to page-aligned */
int vectaligntail(struct iovec *dest)
{
unsigned char *d = (unsigned char *)dest->iov_base;
int len = dest->iov_len;
int ceil_size = (len & (PAGE_PHYS - 1)) ? ((len | (PAGE_PHYS - 1)) + 1) : len;
if (ceil_size > len) {
vectset(dest, 0, ceil_size - len);
}
return ceil_size;
}
/** Remap vectors pointing to various buffers with frame data to vectors used during frame alignment /** Remap vectors pointing to various buffers with frame data to vectors used during frame alignment
* Setup state->writer_params.data_segments[seg_page] ([SEGMENT_GLUE, SEGMENT_FIRST, SEGMENT_SECOND] and * Setup state->writer_params.data_segments[seg_page] ([SEGMENT_GLUE, SEGMENT_FIRST, SEGMENT_SECOND] and
* use /setup next state->writer_params.glue_carry_vec * use /setup next state->writer_params.glue_carry_vec
......
...@@ -63,6 +63,7 @@ void deinit_align_buffers(camogm_state *state); ...@@ -63,6 +63,7 @@ void deinit_align_buffers(camogm_state *state);
void reset_segments(camogm_state *state, int all, int page); void reset_segments(camogm_state *state, int all, int page);
size_t remap_vectors(camogm_state *state); //, struct iovec *chunks); size_t remap_vectors(camogm_state *state); //, struct iovec *chunks);
off64_t lba_to_offset(uint64_t lba); off64_t lba_to_offset(uint64_t lba);
int vectaligntail(struct iovec *dest);
#endif /* _CAMOGM_ALIGN_H */ #endif /* _CAMOGM_ALIGN_H */
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include "camogm_jpeg.h" #include "camogm_jpeg.h"
#include "camogm_read.h" #include "camogm_read.h"
#include "camogm_align.h" #include "camogm_align.h"
#define BUFFER_KVEC //#define BUFFER_KVEC
#define MAX_IMAGE_ALIGNED (4096*256) #define MAX_IMAGE_ALIGNED (4096*256)
/** State file record format. It includes device path in /dev, starting, current and ending LBAs */ /** State file record format. It includes device path in /dev, starting, current and ending LBAs */
#define STATE_FILE_FORMAT "%s\t%llu\t%llu\t%llu\n" #define STATE_FILE_FORMAT "%s\t%llu\t%llu\t%llu\n"
...@@ -62,6 +62,15 @@ ssize_t emul_writev (int fd, const struct iovec *iovec, int count) { ...@@ -62,6 +62,15 @@ ssize_t emul_writev (int fd, const struct iovec *iovec, int count) {
ssize_t wlen, tot_len = 0; ssize_t wlen, tot_len = 0;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (iovec[i].iov_len > 0) { if (iovec[i].iov_len > 0) {
if (iovec[i].iov_len & (PAGE_PHYS -1)){
D0(fprintf(debug_file, "Length not page-aligned: while trying direct writing of %d bytes from %p, data = 0x%llx, segment=%d\n",\
iovec[i].iov_len, iovec[i].iov_base, ((uint64_t*) iovec[i].iov_base)[0],i ));
D0(syslog (LOG_INFO, "Length not page-aligned: while trying direct writing of %d bytes from %p, data = 0x%llx, segment=%d\n",\
iovec[i].iov_len, iovec[i].iov_base, ((uint64_t*) iovec[i].iov_base)[0],i));
debug_level = 6;
return -1;
}
#ifdef BUFFER_KVEC #ifdef BUFFER_KVEC
D6(fprintf(debug_file, "Trying direct writing of %d bytes from %p, data = 0x%llx\n",\ D6(fprintf(debug_file, "Trying direct writing of %d bytes from %p, data = 0x%llx\n",\
iovec[i].iov_len, iovec[i].iov_base, ((uint64_t*) iovec[i].iov_base)[0])); iovec[i].iov_len, iovec[i].iov_base, ((uint64_t*) iovec[i].iov_base)[0]));
...@@ -85,6 +94,8 @@ ssize_t emul_writev (int fd, const struct iovec *iovec, int count) { ...@@ -85,6 +94,8 @@ ssize_t emul_writev (int fd, const struct iovec *iovec, int count) {
wlen = write (fd, iovec[i].iov_base, iovec[i].iov_len); wlen = write (fd, iovec[i].iov_base, iovec[i].iov_len);
#endif #endif
if (wlen < 0) { if (wlen < 0) {
D0(fprintf(debug_file, "Error %d while trying direct writing of %d bytes from %p, data = 0x%llx, segment=%d\n",\
wlen, iovec[i].iov_len, iovec[i].iov_base, ((uint64_t*) iovec[i].iov_base)[0],i ));
return wlen; return wlen;
} else if (wlen < iovec[i].iov_len) { } else if (wlen < iovec[i].iov_len) {
return tot_len + wlen; return tot_len + wlen;
...@@ -446,7 +457,7 @@ int camogm_frame_jpeg(camogm_state *state) ...@@ -446,7 +457,7 @@ int camogm_frame_jpeg(camogm_state *state)
int camogm_end_jpeg(camogm_state *state) // TODO: Resolve multippage ! int camogm_end_jpeg(camogm_state *state) // TODO: Resolve multippage !
{ {
int ret = 0; int ret = 0;
int bytes; int bytes, ceil_size;
ssize_t iovlen; ssize_t iovlen;
if (state->rawdev_op) { if (state->rawdev_op) {
...@@ -458,7 +469,8 @@ int camogm_end_jpeg(camogm_state *state) // TODO: Resolve multippage ! ...@@ -458,7 +469,8 @@ int camogm_end_jpeg(camogm_state *state) // TODO: Resolve multippage !
pthread_cond_wait(&state->writer_params.main_cond, &state->writer_params.writer_mutex); pthread_cond_wait(&state->writer_params.main_cond, &state->writer_params.writer_mutex);
bytes = state->writer_params.glue_carry_vec.iov_len; bytes = state->writer_params.glue_carry_vec.iov_len;
if (bytes > 0) { if (bytes > 0) {
D6(fprintf(debug_file, "Write last block of data, size = %d\n", bytes)); ceil_size = vectaligntail(&state->writer_params.glue_carry_vec);
D1(fprintf(debug_file, "Write last block of data, size = %d, full size = %d\n", bytes, ceil_size));
// the remaining data block is placed in CHUNK_COMMON buffer, write just this buffer // the remaining data block is placed in CHUNK_COMMON buffer, write just this buffer
iovlen = emul_writev(state->writer_params.blockdev_fd, iovlen = emul_writev(state->writer_params.blockdev_fd,
&state->writer_params.glue_carry_vec, &state->writer_params.glue_carry_vec,
...@@ -593,7 +605,7 @@ void *jpeg_writer(void *thread_args) ...@@ -593,7 +605,7 @@ void *jpeg_writer(void *thread_args)
blocks_write = l / PHY_BLOCK_SIZE; // here LBA, 512 blocks_write = l / PHY_BLOCK_SIZE; // here LBA, 512
if (state->writer_params.lba_current + blocks_write <= state->writer_params.lba_end) { // almost always - single write if (state->writer_params.lba_current + blocks_write <= state->writer_params.lba_end) { // almost always - single write
state->writer_params.lba_current += blocks_write; state->writer_params.lba_current += blocks_write;
D3(dbg_us1=get_fpga_usec(state->fd_fparmsall[0], 0)); D2(dbg_us1=get_fpga_usec(state->fd_fparmsall[0], 0));
D6(dbg_pos = lseek(state->writer_params.blockdev_fd, 0, SEEK_CUR)); D6(dbg_pos = lseek(state->writer_params.blockdev_fd, 0, SEEK_CUR));
D6(fprintf(debug_file, "_w02_: starting emul_writev@ %07d\n", dbg_us1)); D6(fprintf(debug_file, "_w02_: starting emul_writev@ %07d\n", dbg_us1));
state->writer_params.writev_run = true; state->writer_params.writev_run = true;
...@@ -601,7 +613,7 @@ void *jpeg_writer(void *thread_args) ...@@ -601,7 +613,7 @@ void *jpeg_writer(void *thread_args)
// iovlen = emul_writev(state->writer_params.blockdev_fd, chunks_iovec[wpage], chunk_index); // iovlen = emul_writev(state->writer_params.blockdev_fd, chunks_iovec[wpage], chunk_index);
iovlen = emul_writev(state->writer_params.blockdev_fd, write_segments, num_write_segments); iovlen = emul_writev(state->writer_params.blockdev_fd, write_segments, num_write_segments);
state->writer_params.writev_run = false; state->writer_params.writev_run = false;
D3(dbg_us=get_fpga_usec(state->fd_fparmsall[0], 0); fprintf(debug_file, "_w03_: finished emul_writev, pos%%block = %ld, pos= %ld @ %07d (+ %07d, +%07d)\n",dbg_pos % PHY_BLOCK_SIZE, dbg_pos,dbg_us, (dbg_us-dbg_us1), (dbg_us-dbg_us2))); D2(dbg_us=get_fpga_usec(state->fd_fparmsall[0], 0); fprintf(debug_file, "_w03_: finished emul_writev, pos%%block = %ld, pos= %ld @ %07d (+ %07d, +%07d)\n",dbg_pos % PHY_BLOCK_SIZE, dbg_pos,dbg_us, (dbg_us-dbg_us1), (dbg_us-dbg_us2)));
D3(syslog (LOG_INFO, "_w03_: finished emul_writev, pos= %ld, len = %d(0x%x) @ %07d (+ %07d, +%07d)", dbg_pos, iovlen, iovlen, dbg_us, (dbg_us-dbg_us1), (dbg_us-dbg_us2))); D3(syslog (LOG_INFO, "_w03_: finished emul_writev, pos= %ld, len = %d(0x%x) @ %07d (+ %07d, +%07d)", dbg_pos, iovlen, iovlen, dbg_us, (dbg_us-dbg_us1), (dbg_us-dbg_us2)));
D3(dbg_us2=dbg_us); D3(dbg_us2=dbg_us);
if (iovlen < l) { if (iovlen < l) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment