SCSI: Use an object_cache for the scatter/gather pool.

All object_caches use locked memory by default; and in fact
the CACHE_UNLOCKED_PAGES flag isn't even implemented at present.
So the locked_pool system is redundant here.
This commit is contained in:
Augustin Cavalier
2024-11-04 16:10:09 -05:00
parent 02857568c9
commit 105f00f768
3 changed files with 25 additions and 35 deletions
@@ -1,7 +1,6 @@
/* /*
* Copyright 2004-2008, Haiku, Inc. All RightsReserved. * Copyright 2004-2024, Haiku, Inc. All rights reserved.
* Copyright 2002-2003, Thomas Kurschel. All rights reserved. * Copyright 2002-2003, Thomas Kurschel. All rights reserved.
*
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -15,11 +14,10 @@
#include <string.h> #include <string.h>
#include <iovec.h> #include <iovec.h>
#include <slab/Slab.h>
#include <algorithm>
static locked_pool_cookie temp_sg_pool; static object_cache* sTempScatterGatherPool = NULL;
static bool static bool
@@ -29,7 +27,7 @@ fill_temp_sg(scsi_ccb *ccb)
scsi_bus_info *bus = ccb->bus; scsi_bus_info *bus = ccb->bus;
uint32 dma_boundary = bus->dma_params.dma_boundary; uint32 dma_boundary = bus->dma_params.dma_boundary;
uint32 max_sg_block_size = bus->dma_params.max_sg_block_size; uint32 max_sg_block_size = bus->dma_params.max_sg_block_size;
uint32 max_sg_blocks = std::min(bus->dma_params.max_sg_blocks, uint32 max_sg_blocks = min_c(bus->dma_params.max_sg_blocks,
(uint32)MAX_TEMP_SG_FRAGMENTS); (uint32)MAX_TEMP_SG_FRAGMENTS);
iovec vec = { iovec vec = {
ccb->data, ccb->data,
@@ -63,7 +61,7 @@ fill_temp_sg(scsi_ccb *ccb)
max_len = (dma_boundary + 1) - max_len = (dma_boundary + 1) -
(temp_sg[cur_idx].address & dma_boundary); (temp_sg[cur_idx].address & dma_boundary);
// restrict size per sg item // restrict size per sg item
max_len = std::min(max_len, (addr_t)max_sg_block_size); max_len = min_c(max_len, (addr_t)max_sg_block_size);
SHOW_FLOW(4, "addr=%#" B_PRIxPHYSADDR ", size=%" B_PRIxPHYSADDR SHOW_FLOW(4, "addr=%#" B_PRIxPHYSADDR ", size=%" B_PRIxPHYSADDR
", max_len=%" B_PRIxADDR ", idx=%" B_PRId32 ", num=%" ", max_len=%" B_PRIxADDR ", idx=%" B_PRId32 ", num=%"
@@ -98,8 +96,6 @@ too_complex:
} }
/** create temporary SG for request */
bool bool
create_temp_sg(scsi_ccb *ccb) create_temp_sg(scsi_ccb *ccb)
{ {
@@ -109,7 +105,7 @@ create_temp_sg(scsi_ccb *ccb)
SHOW_FLOW(3, "ccb=%p, data=%p, data_length=%" B_PRIu32, ccb, ccb->data, SHOW_FLOW(3, "ccb=%p, data=%p, data_length=%" B_PRIu32, ccb, ccb->data,
ccb->data_length); ccb->data_length);
ccb->sg_list = temp_sg = (physical_entry*)locked_pool->alloc(temp_sg_pool); ccb->sg_list = temp_sg = (physical_entry*)object_cache_alloc(sTempScatterGatherPool, 0);
if (temp_sg == NULL) { if (temp_sg == NULL) {
SHOW_ERROR0(2, "cannot allocate memory for IO request!"); SHOW_ERROR0(2, "cannot allocate memory for IO request!");
return false; return false;
@@ -131,24 +127,13 @@ create_temp_sg(scsi_ccb *ccb)
| ((ccb->flags & SCSI_DIR_MASK) == SCSI_DIR_IN ? B_READ_DEVICE : 0)); | ((ccb->flags & SCSI_DIR_MASK) == SCSI_DIR_IN ? B_READ_DEVICE : 0));
err: err:
locked_pool->free(temp_sg_pool, temp_sg); object_cache_free(sTempScatterGatherPool, temp_sg, 0);
return false; return false;
} }
/** cleanup temporary SG list */
void void
uninit_temp_sg(void) cleanup_temp_sg(scsi_ccb *ccb)
{
locked_pool->destroy(temp_sg_pool);
}
/** destroy SG list buffer */
void
cleanup_tmp_sg(scsi_ccb *ccb)
{ {
status_t res; status_t res;
@@ -163,27 +148,32 @@ cleanup_tmp_sg(scsi_ccb *ccb)
panic("Cannot unlock previously locked memory!"); panic("Cannot unlock previously locked memory!");
} }
locked_pool->free(temp_sg_pool, (physical_entry *)ccb->sg_list); object_cache_free(sTempScatterGatherPool, (void*)ccb->sg_list, 0);
// restore previous state // restore previous state
ccb->sg_list = NULL; ccb->sg_list = NULL;
} }
/** create SG list buffer */ //! #pragma mark - initialization/uninitialization
int int
init_temp_sg(void) init_temp_sg(void)
{ {
temp_sg_pool = locked_pool->create( sTempScatterGatherPool = create_object_cache("scsi temp s/g",
MAX_TEMP_SG_FRAGMENTS * sizeof(physical_entry), MAX_TEMP_SG_FRAGMENTS * sizeof(physical_entry), 0,
sizeof(physical_entry) - 1, 0, NULL, NULL, NULL);
B_PAGE_SIZE, MAX_TEMP_SG_LISTS, 1, if (sTempScatterGatherPool == NULL)
"scsi_temp_sg_pool", B_CONTIGUOUS, NULL, NULL, NULL);
if (temp_sg_pool == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
object_cache_set_minimum_reserve(sTempScatterGatherPool, 1);
return B_OK; return B_OK;
} }
void
uninit_temp_sg()
{
delete_object_cache(sTempScatterGatherPool);
}
@@ -279,9 +279,9 @@ void scsi_resubmit_request(scsi_ccb *request);
void scsi_request_finished(scsi_ccb *request, uint num_requests); void scsi_request_finished(scsi_ccb *request, uint num_requests);
// scatter_gather.c // scatter_gather
bool create_temp_sg(scsi_ccb *ccb); bool create_temp_sg(scsi_ccb *ccb);
void cleanup_tmp_sg(scsi_ccb *ccb); void cleanup_temp_sg(scsi_ccb *ccb);
int init_temp_sg(void); int init_temp_sg(void);
void uninit_temp_sg(void); void uninit_temp_sg(void);
@@ -512,7 +512,7 @@ scsi_sync_io(scsi_ccb *request)
acquire_sem(request->completion_sem); acquire_sem(request->completion_sem);
if (tmp_sg) if (tmp_sg)
cleanup_tmp_sg(request); cleanup_temp_sg(request);
} }